本文整理汇总了C#中ThreadStart类的典型用法代码示例。如果您正苦于以下问题:C# ThreadStart类的具体用法?C# ThreadStart怎么用?C# ThreadStart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThreadStart类属于命名空间,在下文中一共展示了ThreadStart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainForm
public MainForm()
{
InitializeComponent();
m_settings = new Settings();
LoadSettings();
// default is HS if not selected
m_stripHS = new Hesari(HS_BASE_ADDRESS);
m_stripKaleva = new Kaleva(KALEVA_BASE_ADDRESS);
if (m_settings.SourceSelection == SelectedSource.HS ||
m_settings.SourceSelection == SelectedSource.NOT_SELECTED)
m_currentStrip = m_stripHS;
else
m_currentStrip = m_stripKaleva;
//Prepare the fade in/out threads that will be called later
ThreadStart fadeInStart = new ThreadStart(FadeIn);
m_fadeIn = new Thread(fadeInStart);
ThreadStart fadeOutStart = new ThreadStart(FadeOut);
m_fadeOut = new Thread(fadeOutStart);
loadResources();
nextPictureBox.Hide();
prevPictureBox.Hide();
this.MouseClick += new MouseEventHandler(MainForm_MouseClick);
ResizeRedraw = true;
SetLoadLabel(true);
LoadCurrent();
}
示例2: LoaderMgr
public LoaderMgr(LoadFunction Function)
{
_Function = Function;
ThreadStart Start = new ThreadStart(Load);
Thread LoadThread = new Thread(Start);
LoadThread.Start();
}
示例3: StartThread
public void StartThread()
{
ThreadStart threadStart = new ThreadStart(UpdateIndex);
Thread thread = new Thread(threadStart);
thread.IsBackground = true;//后台线程
thread.Start();
}
示例4: btnTrain_Click
private void btnTrain_Click(object sender, EventArgs e)
{
this.status.Text = "Training...";
ThreadStart ts = new ThreadStart(ThreadProc);
Thread thread = new Thread(ts);
thread.Start();
}
示例5: MainApp
public MainApp(bool passed_debug_mode, string passed_version, bool passed_verbose)
{
//This checks if there is a new version, and if so alerts user
ThreadStart update_Checker = new ThreadStart(this.check_updates_wrapper);
Thread new_thread = new Thread(update_Checker);
new_thread.Name = "6 to 4 - Update Checker";
new_thread.Start();
//Start the actual window
InitializeComponent();
//Tell all threads, amin is still running, is janky but works
running = 2;
//Starts animating icon while devcon is running
ThreadStart Animation = new ThreadStart(this.animation);
Thread animation_thread = new Thread(Animation);
animation_thread.Name = "6 to 4 - Animation Thread";
animation_thread.Start();
//Set internals from passed
internal_version = passed_version;
internal_debug = passed_debug_mode;
internal_verbose = passed_verbose;
//Easter egg
if (internal_verbose == true)
{
FLASHY = new Visual_Form();
verbose_wrapper();
}
}
示例6: Main
static void Main(string[] args)
{
try
{
// Using Spring's IoC container
ContextRegistry.GetContext();
Spring.Messaging.Amqp.Rabbit.Listener.SimpleMessageListenerContainer container =
ContextRegistry.GetContext().GetObject("MessageListenerContainer") as Spring.Messaging.Amqp.Rabbit.Listener.SimpleMessageListenerContainer;
container.Start();
Console.Out.WriteLine("Server listening...");
IMarketDataService marketDataService =
ContextRegistry.GetContext().GetObject("MarketDataGateway") as MarketDataServiceGateway;
ThreadStart job = new ThreadStart(marketDataService.SendMarketData);
Thread thread = new Thread(job);
thread.Start();
Console.Out.WriteLine("--- Press <return> to quit ---");
Console.ReadLine();
}
catch (Exception e)
{
Console.Out.WriteLine(e);
Console.Out.WriteLine("--- Press <return> to quit ---");
Console.ReadLine();
}
}
示例7: Run
private void Run(ThreadStart userDelegate, ApartmentState apartmentState)
{
lastException = null;
Thread thread = new Thread(
delegate()
{
#if !DEBUG
try
{
#endif
userDelegate.Invoke();
#if !DEBUG
}
catch (Exception e)
{
lastException = e;
}
#endif
});
thread.SetApartmentState(apartmentState);
thread.Start();
thread.Join();
if (ExceptionWasThrown())
ThrowExceptionPreservingStack(lastException);
}
示例8: Main
public static void Main(string[] args)
{
Console.WriteLine ("Starting up websocket...");
Thread thread = null;
WebsocketController ws = new WebsocketController ();
ws.Setup ("ws://websocket.org", "80", "/echo", "echo.websocket.org");
ThreadStart ts = new ThreadStart (() => {
ws.Connect ((str) => {
Console.WriteLine ("OPEN");
ws.Send ("Message 1");
}, (str2) => {
Console.WriteLine ("Received");
//ws.Send ("Message n");
}, (str3)=>{ Console.WriteLine(str3); if(thread != null) thread.Join();},
(str4)=>{ Console.WriteLine(str4); if(thread != null) thread.Join();});
});
thread = new Thread (ts);
thread.Start ();
while (true) {
string s = Console.ReadLine ();
if (!string.IsNullOrEmpty (s))
ws.Send (s);
}
}
示例9: RTSPClient
//creates new client object
public RTSPClient(Socket connectedFrom, string name)
{
try
{
//initialize socket client communicating through
clientSkt = connectedFrom;
//intialize stream with new socket
ntwkstrm = new NetworkStream(clientSkt);
//create delegate for runClient method
ThreadStart runClientMethod = new ThreadStart(this.runClient);
//initialize thread to run runClient
clientThread = new Thread(runClientMethod);
clientThread.Name = name;
//start the thread
clientThread.Start();
}
catch (ThreadStartException tse)
{
//if thread could not be started notify view
referenceToView.Invoke(referenceToView.changeServerStatusTextBox, ("Thread start exception in RTSPClient constructor: "+tse.ToString()));
}
catch (Exception e)
{
//if any other exception occured notify view
referenceToView.Invoke(referenceToView.changeServerStatusTextBox, ("Exception in RTSPClient constructor: "+e.ToString()));
}
}
示例10: Execute
public void Execute(IWorker[] workers, int runningSecs)
{
IAsyncResult[] ar = new IAsyncResult[workers.Length];
int i = 0;
foreach (IWorker w in workers) {
w.WorkerID = i;
ThreadStart t = new ThreadStart(w.DoWork);
ar[i++] = t.BeginInvoke(null, null);
}
//for (int j = 0; j < runningSecs * 10; j++)
//{
// Console.Write(".");
// Thread.Sleep(100);
//}
Thread.Sleep(runningSecs * 1000);
Console.WriteLine();
foreach (IWorker w in workers) {
w.Running = false;
}
bool timeOut = false;
foreach (IAsyncResult a in ar) {
if (!a.IsCompleted)
{
if (!a.AsyncWaitHandle.WaitOne(1000))
timeOut = true;
}
}
if (timeOut)
Console.WriteLine("Timed Out!");
}
示例11: act
public void act(Body bodyIn)
{
body = bodyIn;
ThreadStart act = new ThreadStart (CallToActThread);
Thread ActThread = new Thread (act);
ActThread.Start ();
}
示例12: Enqueue
/// <summary> add jobs to the queue. </summary>
/// <param name="jobs"> should be one or more pairs. </param>
public virtual void Enqueue(ThreadStart[] jobs)
{
lock (toDo) {
foreach (var job in jobs) toDo.Enqueue(job);
if (worker == null) Run();
}
}
示例13: Run
public void Run(string fileName, string arguments)
{
if (isRunning) throw new Exception("This ProcessRunner is already running a process.");
if (!File.Exists(fileName)) throw new FileNotFoundException("The program '"+fileName+"' was not found.",fileName);
isRunning = true;
process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = fileName;
process.StartInfo.Arguments = arguments;
process.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
process.Start();
outputReader = process.StandardOutput;
errorReader = process.StandardError;
// we need to wait for all 3 of our threadpool operations to finish
// (processexit, readoutput, readerror)
tasksFinished = 0;
// do our waiting on the threadpool
ThreadStart waitForExitDel = new ThreadStart(process.WaitForExit);
waitForExitDel.BeginInvoke(new AsyncCallback(TaskFinished),null);
// also read outputs on the threadpool
ThreadStart readOutputDel = new ThreadStart(ReadOutput);
ThreadStart readErrorDel = new ThreadStart(ReadError);
readOutputDel.BeginInvoke(new AsyncCallback(TaskFinished),null);
readErrorDel.BeginInvoke(new AsyncCallback(TaskFinished),null);
}
示例14: StressTest
public void StressTest()
{
queue = new ProducerConsumerQueue();
ThreadStart consumerMethod = new ThreadStart(accumulatingRunner);
Thread consumerThread = new Thread(consumerMethod);
consumerThread.Start();
Thread.Sleep(500);
ArrayList threads = new ArrayList();
for (int i = 0; i < 100; i++)
{
ThreadStart producerMethod = new ThreadStart(producingThread);
threads.Add(new Thread(producerMethod));
}
for (int i = 0; i < 100; i++)
{
((Thread)threads[i]).Start();
}
for (int i = 0; i < 100; i++)
{
((Thread)threads[i]).Join();
}
consumerThread.Join();
Assert.AreEqual(0, queue.Count);
Assert.AreEqual(100000, staticCounter);
for (int i = 0; i < 100000; i++)
{
Assert.AreEqual(i, (int)accumulatedResults[i], "Failed at index " + i);
}
}
示例15: Main
static void Main(string[] args)
{
Program PC = new Program();
ThreadStart TS = new ThreadStart(PC.ShowTime);
Thread t = new Thread(TS);
t.Start(); Console.ReadLine();
}