Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C#: Simultaneous threads???

Posted on 2004-09-30
3
Medium Priority
?
1,346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: 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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

704 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