Solved

C#: Simultaneous threads???

Posted on 2004-09-30
3
1,341 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 200 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 200 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 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