troubleshooting Question

How to create a thread for this code?

Avatar of YANKAUSKAS
YANKAUSKASFlag for United States of America asked on
.NET ProgrammingC#Visual C++.NET
1 Comment1 Solution247 ViewsLast Modified:
have the code bellow, because all the code is in the Main program, the program will never fully start, the mr.response will not be printed out because the monitorCall always null if there is no call call to the channel which is monitored. I want this program still print out the mr.response when there is no call call to channel. I know we have to use thread, could you suggest me how to use thread in this code? Thank you very much!

static void Main(string[] args)
        {
	// Initialization here...           
            try
            {
                // Connect to Remote server ...
            }
            catch (Exception ex)
            {
            }
 
            Console.WriteLine("Monitor the phone.");
            // Wait for Link event
            LinkEventHandler le = new LinkEventHandler(dam_Link);
            manager.Link += le;
            while (monitorCall == null)
            {
                System.Threading.Thread.Sleep(100);
            }
            manager.Link -= le;
            // Now send Monitor action
            MonitorAction ma = new MonitorAction();
             try
            {
                ManagerResponse mr = manager.Connection.SendAction(ma, 10000);
                Console.WriteLine("Monitor Call" + "\n\tResponse:" + mr.Response);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros