Solved

C#: Simultaneous threads???

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now