Hello, I am trying to setup a Visual Basic "Console" application for
searching Outlook folders. To this end I am trying to implement a Handler
for the Outlook.Application.AdvancedSearchComplete Event. The problem I
have is that the application finishes and exits before the AdvanceSearch, so
the Event Handler in never called. If I delay the end of the application,
for example, by having message box right after the call to AdvancedSearch,
the search completes, its handler is executed, and it correctly reports the
number of matched emails. Thus, this works:
Imports Microsoft.Office.Interop
Module Module1
Sub Main()
Dim App As New Outlook.Application
AddHandler App.AdvancedSearchComplete, AddressOf
App_AdvancedSearchComplete
App.AdvancedSearch("'Inbox'", "urn:schemas:httpmail:subject LIKE
'%test'", False, "TestSearch")
MsgBox("pause")
End Sub
Public Sub App_AdvancedSearchComplete(ByVal oSearch As Outlook.Search)
MsgBox("Search done. Found " & oSearch.Results.Count & " emails")
End Sub
End Module
However, if I remove the msgbox call under Main, App_AdvancedSearchComplete
is not executed.
I tried the same code on a "Windows" application, and it works fine, but I
would prefer to use a console application.
I would appreciate any suggestions anyone would have.
Thanks in advance.
federico 4 5656
On Jan 9, 3:42 pm, "federico" <feder...@michosa.comwrote:
Hello, I am trying to setup a Visual Basic "Console" application for
searching Outlook folders. To this end I am trying to implement a Handler
for the Outlook.Application.AdvancedSearchComplete Event. The problem I
have is that the application finishes and exits before the AdvanceSearch, so
the Event Handler in never called. If I delay the end of the application,
for example, by having message box right after the call to AdvancedSearch,
the search completes, its handler is executed, and it correctly reports the
number of matched emails. Thus, this works:
Imports Microsoft.Office.Interop
Module Module1
Sub Main()
Dim App As New Outlook.Application
AddHandler App.AdvancedSearchComplete, AddressOf
App_AdvancedSearchComplete
App.AdvancedSearch("'Inbox'", "urn:schemas:httpmail:subject LIKE
'%test'", False, "TestSearch")
MsgBox("pause")
End Sub
Public Sub App_AdvancedSearchComplete(ByVal oSearch As Outlook.Search)
MsgBox("Search done. Found " & oSearch.Results.Count & " emails")
End Sub
End Module
However, if I remove the msgbox call under Main, App_AdvancedSearchComplete
is not executed.
I tried the same code on a "Windows" application, and it works fine, but I
would prefer to use a console application.
I would appreciate any suggestions anyone would have.
Thanks in advance.
federico
Personally, I also use "Console.Read()" to stop a console application
from exiting. This will cause the console app to wait for the user to
hit the enter key before exiting. You could also set a boolean flag
that is checked on a loop (with a thread sleep call to reduce memory/
resource use) that is only set after your handler for the
AdvancedSearchComplete event has fired.
Thanks,
Seth Rowe [MVP]
Ditto.
Either put a
Console.WriteLine("Press ENTER to Exit");
Console.ReadLine();
at the end of your program...or set a flag that only allows exist after the
handler has executed.
"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:b9**********************************@j20g2000 hsi.googlegroups.com...
On Jan 9, 3:42 pm, "federico" <feder...@michosa.comwrote:
>Hello, I am trying to setup a Visual Basic "Console" application for searching Outlook folders. To this end I am trying to implement a Handler for the Outlook.Application.AdvancedSearchComplete Event. The problem I have is that the application finishes and exits before the AdvanceSearch, so the Event Handler in never called. If I delay the end of the application, for example, by having message box right after the call to AdvancedSearch, the search completes, its handler is executed, and it correctly reports the number of matched emails. Thus, this works:
Imports Microsoft.Office.Interop Module Module1 Sub Main() Dim App As New Outlook.Application AddHandler App.AdvancedSearchComplete, AddressOf App_AdvancedSearchComplete App.AdvancedSearch("'Inbox'", "urn:schemas:httpmail:subject LIKE '%test'", False, "TestSearch") MsgBox("pause") End Sub Public Sub App_AdvancedSearchComplete(ByVal oSearch As Outlook.Search) MsgBox("Search done. Found " & oSearch.Results.Count & " emails") End Sub End Module
However, if I remove the msgbox call under Main, App_AdvancedSearchComplete is not executed.
I tried the same code on a "Windows" application, and it works fine, but I would prefer to use a console application.
I would appreciate any suggestions anyone would have.
Thanks in advance.
federico
Personally, I also use "Console.Read()" to stop a console application
from exiting. This will cause the console app to wait for the user to
hit the enter key before exiting. You could also set a boolean flag
that is checked on a loop (with a thread sleep call to reduce memory/
resource use) that is only set after your handler for the
AdvancedSearchComplete event has fired.
Thanks,
Seth Rowe [MVP]
"federico" <fe******@michosa.comschrieb:
Hello, I am trying to setup a Visual Basic "Console" application for
searching Outlook folders. To this end I am trying to implement a Handler
for the Outlook.Application.AdvancedSearchComplete Event. The problem I
have is that the application finishes and exits before the AdvanceSearch,
so the Event Handler in never called. If I delay the end of the
application, for example, by having message box right after the call to
AdvancedSearch, the search completes, its handler is executed, and it
correctly reports the number of matched emails. Thus, this works:
Imports Microsoft.Office.Interop
Module Module1
Sub Main()
Dim App As New Outlook.Application
AddHandler App.AdvancedSearchComplete, AddressOf
App_AdvancedSearchComplete
App.AdvancedSearch("'Inbox'", "urn:schemas:httpmail:subject LIKE
'%test'", False, "TestSearch")
MsgBox("pause")
End Sub
Public Sub App_AdvancedSearchComplete(ByVal oSearch As Outlook.Search)
MsgBox("Search done. Found " & oSearch.Results.Count & " emails")
End Sub
End Module
You can use 'ManualResetEvent' for this purpose. This doesn't prevent the
application from terminating after the event occured (which using
'Console.Read'/'Console.ReadLine' does).
\\\
Imports System.Threading
Friend Module Program
Public Sub Main()
Dim EventOccured As New ManualResetEvent(False)
Dim Worker As New Worker(EventOccured)
Dim WorkerThread As New Thread(AddressOf Worker.DoWork)
Console.WriteLine("Work started at {0}.", Now)
WorkerThread.Start()
EventOccured.WaitOne()
Console.WriteLine("Work finished at {0}.", Now)
End Sub
End Module
Friend Class Worker
Private m_EventOccured As ManualResetEvent
Public Sub New(ByVal Notifier As ManualResetEvent)
m_EventOccured = Notifier
End Sub
Public Sub DoWork()
Thread.Sleep(5000)
m_EventOccured.Set()
End Sub
End Class
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Thanks so much. The flag works nicely.
"federico" <fe******@michosa.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hello, I am trying to setup a Visual Basic "Console" application for
searching Outlook folders. To this end I am trying to implement a Handler
for the Outlook.Application.AdvancedSearchComplete Event. The problem I
have is that the application finishes and exits before the AdvanceSearch,
so the Event Handler in never called. If I delay the end of the
application, for example, by having message box right after the call to
AdvancedSearch, the search completes, its handler is executed, and it
correctly reports the number of matched emails. Thus, this works:
Imports Microsoft.Office.Interop
Module Module1
Sub Main()
Dim App As New Outlook.Application
AddHandler App.AdvancedSearchComplete, AddressOf
App_AdvancedSearchComplete
App.AdvancedSearch("'Inbox'", "urn:schemas:httpmail:subject LIKE
'%test'", False, "TestSearch")
MsgBox("pause")
End Sub
Public Sub App_AdvancedSearchComplete(ByVal oSearch As Outlook.Search)
MsgBox("Search done. Found " & oSearch.Results.Count & " emails")
End Sub
End Module
However, if I remove the msgbox call under Main,
App_AdvancedSearchComplete is not executed.
I tried the same code on a "Windows" application, and it works fine, but I
would prefer to use a console application.
I would appreciate any suggestions anyone would have.
Thanks in advance.
federico This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Christopher W. Douglas |
last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a
method that handles several events, such as closing a form and changing the
visible status of a form. I have some code...
|
by: Rohit |
last post by:
Hi,
Threads in the .NET Framework 1.1 (and possibly in 1.0 also) leak "Event"
handles, by Event handles I mean Win32 Event handles which can be monitored
using the ProcessExplorer from...
|
by: Wayne |
last post by:
I have an application where I added a comment as the first line of my Config
file, as I found out I can't do this. However, an entry was made in the
event log about the error (Source = .net...
|
by: aaj |
last post by:
Hi all
I have an automated application, that runs in the middle of the night.
If certain 'non system' errors occur (things like malformed files, missing
files etc..), I send an automatic Email...
|
by: brandon |
last post by:
Anybody out there know how I could go about handling, in a systray'd
app, the windows message that the desktop is going to be locked? This
way the application can react whenever the Win+L or...
|
by: geskerrett |
last post by:
We have been asked to develop and application for a client that is a
'notification" system. We would like to use python, but are struggling
to find the right starting point. Any suggestions, tips...
|
by: dvestal |
last post by:
Suppose I have this:
class C {
public delegate void MyEventHandler();
public event MyEventHandler MyEvent;
public void foo() {
MyEvent(); // NullReferenceException?
}
}
|
by: marian.kovac |
last post by:
Hi, I have this simple sample code:
class SearchRange
{
static int m = 0;
static void Main(string args)
{
Discover discover = new Discover();
// Add discovered device handler
|
by: cnixuser |
last post by:
Hello, I have a basic application written which is designed to data over a serial cable and then receive a response back. I am not getting any triggers to my data received event. I have tried...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |