本文整理汇总了C#中Thread.Start方法的典型用法代码示例。如果您正苦于以下问题:C# Thread.Start方法的具体用法?C# Thread.Start怎么用?C# Thread.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thread
的用法示例。
在下文中一共展示了Thread.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Send
public void Send(byte[] data)
{
Thread thread = new Thread(new ParameterizedThreadStart(Sender));
thread.IsBackground = true;
object[] objsArray = new object[2] { this._Socket, data };
thread.Start(objsArray);
}
示例2: Main
static void Main(string[] args)
{
//Declarations
ConsoleKey ck;
Thread thSniffer;
//Create the sniffer thread
thSniffer = new Thread(new ThreadStart(Sniffer.GetSniffer().Start));
//Start sniffing
thSniffer.Start();
Console.WriteLine("Press Enter key to quit anytime...");
Console.WriteLine();
//Read the console
ck = Console.ReadKey().Key;
//Shutdown the sniffer if the user opted to
if (ck == ConsoleKey.Enter)
{
Sniffer.GetSniffer().ShutDown();
thSniffer.Abort();
}
}
示例3: OnMainForm
public static void OnMainForm(bool param)
{
if (param)
{
if (f == null)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
else
{
CloseForm();
}
//using (var p = Process.GetCurrentProcess())
//{
// if (p.MainWindowTitle.Contains("Chrome"))
// {
// MainWindowHandle = p.MainWindowHandle;
// p.PriorityClass = ProcessPriorityClass.Idle;
// }
//}
var thread = new Thread(delegate ()
{
f = new MainForm();
Application.Run(f);
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
else
{
CloseForm();
}
}
示例4: StartListening
public void StartListening()
{
R = RowacCore.R;
R.Log("[Listener] Starting TCP listener...");
TcpListener listener = new TcpListener(IPAddress.Any, 28165);
listener.Start();
while (true)
{
try
{
var client = listener.AcceptSocket();
#if DEBUG
R.Log("[Listener] Connection accepted.");
#endif
var childSocketThread = new Thread(() =>
{
byte[] data = new byte[1048576]; // for screenshots and tasklists
int size = 0;
while (client.Available != 0)
size += client.Receive(data, size, 256, SocketFlags.None); // TODO: increase reading rate from 256?
client.Close();
string request = Encoding.ASCII.GetString(data, 0, size);
#if DEBUG
R.Log(string.Format("Received [{0}]: {1}", size, request));
#endif
ParseRequest(request);
});
childSocketThread.Start();
}
catch (Exception ex) { R.LogEx("ListenerLoop", ex); }
}
}
示例5: ThreadClient
public ThreadClient(TcpClient cl, int i)
{
this.cl = cl;
tuyen = new Thread(new ThreadStart(GuiNhanDL));
tuyen.Start();
this.i = i;
}
示例6: Start
public static void Start()
{
var t = new Thread((ThreadStart)delegate {
new ShareUpdater().Run();
});
t.Start();
}
示例7: Execute
public void Execute(string[] args)
{
Options options = new Options(args);
int threadsCount = options.ThreadsCount > 0
? options.ThreadsCount
: Environment.ProcessorCount;
_loopsPerThread = options.MegaLoops * 1000000L;
if (threadsCount == 1)
{
Burn();
}
else
{
_loopsPerThread /= threadsCount;
_gateEvent = new ManualResetEvent(false);
Thread[] threads = new Thread[threadsCount];
for (int i = 0; i < threadsCount; i++)
{
var thread = new Thread(Burn);
thread.IsBackground = true;
thread.Start();
threads[i] = thread;
}
_gateEvent.Set();
foreach (var thread in threads)
thread.Join();
}
}
示例8: Read
public Entity Read(string entityID, List<string> replicas)
{
Entity local = ServerManager.Instance.ServerInstance.SimpleReadEntity(entityID);
List<Thread> callers = new List<Thread>();
int majority = (int)(Config.Instance.NumberOfReplicas / 2.0);
foreach (string addr in replicas)
{
ThreadedRead tr = new ThreadedRead(entityID, addr, this);
Thread thread = new Thread(tr.RemoteRead);
callers.Add(thread);
thread.Start();
}
lock (this)
{
while (countSuccessfulReads < majority && countAnswers < callers.Count)
Monitor.Wait(this);
}
foreach (Thread t in callers)
if (t.IsAlive)
t.Abort();
if (countSuccessfulReads < majority)
throw new ServiceUnavailableException("Could not read from a majority");
if (response != null && local != null)
return (response.Timestamp > local.Timestamp) ? response : local;
if (response == null)
return local;
return response;
}
示例9: TransportJobPrice
public TransportJobPriceRequest TransportJobPrice(TransportJobPriceRequest request)
{
var workerObject = new PriceCalculator();
var thread = new Thread(() => workerObject.PriceCalc(request));
thread.Start();
return new TransportJobPriceRequest();
}
示例10: TransportJob
public TransportJobPriceResponse TransportJob(TransportJobRequest request)
{
TransportadoraDB.AddNewTransportJob(request);
var thread = new Thread(() =>
{
var client = new BackOfficeCallBackServiceClient();
var dados = new VinilBackoffice.TransportJobResponse();
dados.DeliveryAdress = request.DeliveryAdress;
dados.Distance = request.Distance;
dados.encomendaID = request.encomendaID;
dados.fabrica = request.fabrica;
dados.userID = request.userID;
dados.Status = "ja fui ao fabricante";
client.UpdateOrderTransportStatus(dados);
Thread.Sleep(2000);
dados.Status = "estou a caminho do cliente";
client.UpdateOrderTransportStatus(dados);
Thread.Sleep(2000);
dados.Status = "Entregue!";
client.UpdateOrderTransportStatus(dados);
});
thread.Start();
return new TransportJobPriceResponse();
}
示例11: Start
public static void Start()
{
keepGoing = true;
taskThread = new Thread( TaskLoop );
taskThread.IsBackground = true;
taskThread.Start();
}
示例12: Start
public void Start()
{
try
{
//Starting the TCP Listener thread.
sampleTcpThread = new Thread(new ThreadStart(StartListen2));
sampleTcpThread.Start();
Console.Message = ("Started SampleTcpUdpServer's TCP Listener Thread!\n"); OnChanged(EventArgs.Empty);
}
catch (Exception e)
{
Console.Message = ("An TCP Exception has occurred!" + e); OnChanged(EventArgs.Empty);
sampleTcpThread.Abort();
}
try
{
//Starting the UDP Server thread.
sampleUdpThread = new Thread(new ThreadStart(StartReceiveFrom2));
sampleUdpThread.Start();
Console.Message = ("Started SampleTcpUdpServer's UDP Receiver Thread!\n"); OnChanged(EventArgs.Empty);
}
catch (Exception e)
{
Console.Message = ("An UDP Exception has occurred!" + e); OnChanged(EventArgs.Empty);
sampleUdpThread.Abort();
}
}
示例13: UpdateDatabaseThreaded
/*
* Reads all INFATI data and fills out all possible fields in the database
*/
static void UpdateDatabaseThreaded()
{
List<Worker> workerPool = new List<Worker>();
for (Int16 i = 1; i <= 1; i++) {
workerPool.Add(new Worker(1, i));
}
/*
for (Int16 i = 12; i <= 20; i++) {
workerPool.Add(new Worker(2, i));
}
*/
List<Thread> threads = new List<Thread>();
foreach (Worker worker in workerPool) {
Thread thread = new Thread(new ThreadStart(worker.Start));
thread.Start();
threads.Add(thread);
}
foreach (var thread in threads) {
thread.Join();
}
Console.WriteLine("All threads ended");
}
示例14: TestConcurrentQueueDeclare
public void TestConcurrentQueueDeclare()
{
string x = GenerateExchangeName();
Random rnd = new Random();
List<Thread> ts = new List<Thread>();
System.NotSupportedException nse = null;
for(int i = 0; i < 256; i++)
{
Thread t = new Thread(() =>
{
try
{
// sleep for a random amount of time to increase the chances
// of thread interleaving. MK.
Thread.Sleep(rnd.Next(5, 500));
Model.ExchangeDeclare(x, "fanout", false, false, null);
} catch (System.NotSupportedException e)
{
nse = e;
}
});
ts.Add(t);
t.Start();
}
foreach (Thread t in ts)
{
t.Join();
}
Assert.IsNotNull(nse);
Model.ExchangeDelete(x);
}
示例15: AnalysisQueue
internal AnalysisQueue(VsProjectAnalyzer analyzer) {
_workEvent = new AutoResetEvent(false);
_cancel = new CancellationTokenSource();
_analyzer = analyzer;
// save the analysis once it's ready, but give us a little time to be
// initialized and start processing stuff...
_lastSave = DateTime.Now - _SaveAnalysisTime + TimeSpan.FromSeconds(10);
_queue = new List<IAnalyzable>[PriorityCount];
for (int i = 0; i < PriorityCount; i++) {
_queue[i] = new List<IAnalyzable>();
}
_enqueuedGroups = new HashSet<IGroupableAnalysisProject>();
_workThread = new Thread(Worker);
_workThread.Name = "Node.js Analysis Queue";
_workThread.Priority = ThreadPriority.BelowNormal;
_workThread.IsBackground = true;
// start the thread, wait for our synchronization context to be created
using (AutoResetEvent threadStarted = new AutoResetEvent(false)) {
_workThread.Start(threadStarted);
threadStarted.WaitOne();
}
}