954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to wait for execution of event/thread

Hello,

I would need a help from you with my application. I received a lot of (email)sms, and I don't want to store them in my regular sms-phone database. I receive them quite a lot (daily - 40), so mostly I just read and delete them. So I created an application, to not to store them. I managed to create it in WinApi, but I had problems with winForm's limitation. Therefore I went to console application, as Windows Mobiles (6.1) hava no services.
I have another app, which register the event and do some other settings. But I have problem with show abilities.

I have created an Messageinterceptor to get and show messages. It works good in WinApi, but in alternative, console application, I have a problem with the events.

Main code:

static void Main(string[] args)
        {
            MessageInterceptor MySMStaker = new MessageInterceptor("iSMS_process");
            MySMStaker.MessageReceived += new MessageInterceptorEventHandler(SmsInterceptor_MessageReceived);

            MessageBox.Show("");
        }


In the "SmsInterceptor_MessageReceived" it show a MessageBox with some sms text. That is as expected, where as the smsbody is from event (e). See below:

static void SmsInterceptor_MessageReceived(object sender, MessageInterceptorEventArgs e)
        {
            SmsMessage newMessage = e.Message as SmsMessage;
	    MessageBox.Show
        	(
                 newMessage.Body,
                 newMessage.Received.ToLocalTime().ToShortDateString() + "|" + newMessage.Received.ToLocalTime().ToShortTimeString());
	}


I would like from the application to work like:Sms received,
Console application is called by event,
Console application read "one" event and show the Messagebox with sms text,
Console application close itself

Problem is that I don't have an idea how to "pause" the main thread to not read any onther event, while the event is read as MessageBox. If I remove the MessageBox.Show("");, it show nothing and nothing is receive, which is obvious, as nothing is waiting for the event to execute.
I tried Thread.Sleep(0) and Thread.Sleep(Threading.TimeOut.Infinite), but I got the same result. I also tried some testing with creating dummy Thread, but none was good. I am not very skilled with asynchronous event and google didn't had a good results.


Can you please help me with it?

Seten
Junior Poster
168 posts since Oct 2005
Reputation Points: 9
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: