Solved

C#: Simultaneous threads???

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

622 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