Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C#: Simultaneous threads???

Posted on 2004-09-30
3
Medium Priority
?
1,348 Views
Last Modified: 2008-03-03
I have a unique project running two seperate processes. They must both run at the same time. I've tested Thread Pooling, Sleep, Wait, etc... and have conluded I must have to seperate Apps running simultaneously. Any suggestions are welcome.........

Q. How can I 'call' the second App to open and start working from the first App???

0
Comment
Question by:kvnsdr
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
CrazyIvan007 earned 800 total points
ID: 12190393
Running Threads Simultaneous works with

Thread[] t_Thread = new Thread[2];

t_Thread[0] = new Thread(new Threadstart(this.threadobject1));
t_Thread[1] = new Thread(new Threadstart(this.threadobject2));

t_Thread[0].Start();
t_Thread[1].Start();

If you want to wait the app until the Threads are finished (but then the UI Thread freeze)

t_Thread[0].Wait();
t_Thread[1].Wait();

private void threadobject1()
{
// Your Code for Thread1
}

private void threadobject2()
{
// Your Code for Thread2
}


If you want to pass Datas to the Threads you have to use Helper Classes, f.e.

HelperClass1 _hc1 = new HelperClass(string1, string2);
HelperClass2 _hc2 = new HelperClass(string1, string2);

And then start the Thread with

... ThreadStart(_hc1.threadobject1);






After that if you wan't to access the UI Controls (like putting out status) you have to Invoke it with delegates
0
 
LVL 1

Author Comment

by:kvnsdr
ID: 12190746
Excellent......... Now when I exit the App, the threads or process keeps running until I 'End Process' in 'Windows Task Manager -> Processes' (Windows 2000 Server)...

Q. How do I stop the threads after the application exits ???

0
 
LVL 1

Assisted Solution

by:CrazyIvan007
CrazyIvan007 earned 800 total points
ID: 12190862
if ((t_Thread[0] != null) && (t_Thread[0].IsAlive)) { t_Thread[0].Abort(); }
if ((t_Thread[1] != null) && (t_Thread[1].IsAlive)) { t_Thread[1].Abort(); }

That kills the Threads
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question