473,385 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

URGEN HELP: Starting a process from my application ???

Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=================================================

.......
Dim myProcessStartInfo As New ProcessStartInfo(m_sIntouchInstallPath &
"\view.exe")
myProcessStartInfo.UseShellExecute = False
myProcess.StartInfo = myProcessStartInfo
myProcess.StartInfo.WindowStyle =
ProcessWindowStyle.Normal

myProcess.Start()
AddHandler myProcess.Exited, AddressOf MyProcessExited
' Set 'EnableRaisingEvents' to true, to raise
'Exited' event when process is terminated.
myProcess.EnableRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNullString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
.......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge
Jul 21 '05 #1
12 2844
I suggest calling myProcess.WaitForExit(1000) in your while loop. This will
give control to other apps (allowing them to process events) and come back to
your loop after a second (1000 mS).

Regards
John

"serge calderara" wrote:
Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=================================================

......
Dim myProcessStartInfo As New ProcessStartInfo(m_sIntouchInstallPath &
"\view.exe")
myProcessStartInfo.UseShellExecute = False
myProcess.StartInfo = myProcessStartInfo
myProcess.StartInfo.WindowStyle =
ProcessWindowStyle.Normal

myProcess.Start()
AddHandler myProcess.Exited, AddressOf MyProcessExited
' Set 'EnableRaisingEvents' to true, to raise
'Exited' event when process is terminated.
myProcess.EnableRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNullString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge

Jul 21 '05 #2
HI john,

Thnaks for your answer. I give a try by changing my code according to your
advise but it is still the same. Having this while loop place my application
in a Non Responding satus and my process is partialy started but lock at the
welcome screen.

Now if I close my main application with task manager, my started process
continue to execute and open fully .....

Any other idea how to start that process and retrive its handle without
locking the whole application ? it seems it all runs in the same context and
threads that is may be the reason.. if so shouzdl I create a thread that
launch my process ?

The modify loop isas follow :
While m_iViewerHandle = 0
------> myProcess.WaitForExit(1000)
System.Threading.Thread.Sleep(500)
m_iViewerHandle = FindWindow(vbNullString, "VIEW
- " & m_sApplicationPath)
End While

Thnaks for your help
serge

"John Roper" wrote:
I suggest calling myProcess.WaitForExit(1000) in your while loop. This will
give control to other apps (allowing them to process events) and come back to
your loop after a second (1000 mS).

Regards
John

"serge calderara" wrote:
Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=================================================

......
Dim myProcessStartInfo As New ProcessStartInfo(m_sIntouchInstallPath &
"\view.exe")
myProcessStartInfo.UseShellExecute = False
myProcess.StartInfo = myProcessStartInfo
myProcess.StartInfo.WindowStyle =
ProcessWindowStyle.Normal

myProcess.Start()
AddHandler myProcess.Exited, AddressOf MyProcessExited
' Set 'EnableRaisingEvents' to true, to raise
'Exited' event when process is terminated.
myProcess.EnableRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNullString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge

Jul 21 '05 #3
Hi Serge,

Your app will freeze while you wait and sleep, but the new process
shouldn't. Perhaps it would be worth trying UseShellExecute = True? You only
really need to set this to False if you are going to change stdin/out.

Cheers
John

"serge calderara" wrote:
HI john,

Thnaks for your answer. I give a try by changing my code according to your
advise but it is still the same. Having this while loop place my application
in a Non Responding satus and my process is partialy started but lock at the
welcome screen.

Now if I close my main application with task manager, my started process
continue to execute and open fully .....

Any other idea how to start that process and retrive its handle without
locking the whole application ? it seems it all runs in the same context and
threads that is may be the reason.. if so shouzdl I create a thread that
launch my process ?

The modify loop isas follow :
While m_iViewerHandle = 0
------> myProcess.WaitForExit(1000)
System.Threading.Thread.Sleep(500)
m_iViewerHandle = FindWindow(vbNullString, "VIEW
- " & m_sApplicationPath)
End While

Thnaks for your help
serge

"John Roper" wrote:
I suggest calling myProcess.WaitForExit(1000) in your while loop. This will
give control to other apps (allowing them to process events) and come back to
your loop after a second (1000 mS).

Regards
John

"serge calderara" wrote:
Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=================================================

......
Dim myProcessStartInfo As New ProcessStartInfo(m_sIntouchInstallPath &
"\view.exe")
myProcessStartInfo.UseShellExecute = False
myProcess.StartInfo = myProcessStartInfo
myProcess.StartInfo.WindowStyle =
ProcessWindowStyle.Normal

myProcess.Start()
AddHandler myProcess.Exited, AddressOf MyProcessExited
' Set 'EnableRaisingEvents' to true, to raise
'Exited' event when process is terminated.
myProcess.EnableRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNullString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge

Jul 21 '05 #4
It sounds like the process is starting on the same thread. Might be good to
start the process on another thread and let it invoke a callback method when
it is ready. This will prevent your primary thread from hanging.

The following example is in C#.
1. Make sure the namespace System.Threading is imported:
using System.Threading;

2. Instead of starting the process, queue the process into the thread pool.
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));

3. The ThreadProc procedure should be declared, which actually starts the
process on the new thread.
private void ThreadProc(object stateInfo)
{
// Start the process here.
// Whenever the process is finished, it can execute another method
// which continues where this leaves off.
}

Hope that helps.

--
Jason Whitted

"serge calderara" wrote:
Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=================================================

......
Dim myProcessStartInfo As New ProcessStartInfo(m_sIntouchInstallPath &
"\view.exe")
myProcessStartInfo.UseShellExecute = False
myProcess.StartInfo = myProcessStartInfo
myProcess.StartInfo.WindowStyle =
ProcessWindowStyle.Normal

myProcess.Start()
AddHandler myProcess.Exited, AddressOf MyProcessExited
' Set 'EnableRaisingEvents' to true, to raise
'Exited' event when process is terminated.
myProcess.EnableRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNullString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge

Jul 21 '05 #5
HI John,

I I use what you mentionned it freeze everything, my application and the
process I start.

I have mange to make it working by using the following code :
==============================================
myProcess.EnableRaisingEvents = True
myProcess.WaitForInputIdle(20000)

If myProcess.Responding Then
m_iViewerHandle =
myProcess.MainWindowHandle.ToInt32
Dim sTitle As String
sTitle = myProcess.MainWindowTitle
Me.m_ObjMessagePrvd.LogMessage("Process has ben
catch with hdl: " & CStr(m_iViewerHandle) & " and WIndow name as : " &
sTitle, TraceLevel.Info)
Else
myProcess.Kill()
End If
Then I can play with the timeout value for
myProcess.WaitForInputIdle(20000) as a parameter.

THis the launching application start my process and wait for the idle state
of the launched process, if it fails during that time then this means trouble
with the process.

If I use this, what is the best way afterwards to retrive the handle of the
process window by its window name ?

I use the following if my process is responding:
==================================
m_iViewerHandle = myProcess.MainWindowHandle.ToInt32
Dim sTitle As String
sTitle = myProcess.MainWindowTitle

but I het m_iViewerHandle= 0 and sTitle="", it seems that even the process
is responding the main window is noit yet ready

thnaks for your help
serge

"John Roper" wrote:
Hi Serge,

Your app will freeze while you wait and sleep, but the new process
shouldn't. Perhaps it would be worth trying UseShellExecute = True? You only
really need to set this to False if you are going to change stdin/out.

Cheers
John

"serge calderara" wrote:
HI john,

Thnaks for your answer. I give a try by changing my code according to your
advise but it is still the same. Having this while loop place my application
in a Non Responding satus and my process is partialy started but lock at the
welcome screen.

Now if I close my main application with task manager, my started process
continue to execute and open fully .....

Any other idea how to start that process and retrive its handle without
locking the whole application ? it seems it all runs in the same context and
threads that is may be the reason.. if so shouzdl I create a thread that
launch my process ?

The modify loop isas follow :
While m_iViewerHandle = 0
------> myProcess.WaitForExit(1000)
System.Threading.Thread.Sleep(500)
m_iViewerHandle = FindWindow(vbNullString, "VIEW
- " & m_sApplicationPath)
End While

Thnaks for your help
serge

"John Roper" wrote:
I suggest calling myProcess.WaitForExit(1000) in your while loop. This will
give control to other apps (allowing them to process events) and come back to
your loop after a second (1000 mS).

Regards
John

"serge calderara" wrote:

> Dear all,
>
> I have an application which is suppose to start another executable process.
> As soon as that process is running, I need to retrive its handle. The
> problem of the particular process I am starting is that it has a welcome
> window first which gets displayed and then the real windows after a while,in
> other words it means that the process name is the same, but the handle I need
> to retrive is the one from the final window and not the welome window.
>
> So in real that means that from my main application I need to wait for a
> while that the whol process started is really finishe to load befor getting
> the real handle I am interresting on. The problem I get if I set a kind of
> small loop in my main application is that the process I try to start is
> freezed as long as I remain in my main application loop.
>
> In other words how can I start my process, asynchronously from my main
> application and then after a while try to retrive its handle ??
>
> For you infor I use the follwoing code to starting it:
> =================================================
>
> ......
> Dim myProcessStartInfo As New ProcessStartInfo(m_sIntouchInstallPath &
> "\view.exe")
> myProcessStartInfo.UseShellExecute = False
> myProcess.StartInfo = myProcessStartInfo
> myProcess.StartInfo.WindowStyle =
> ProcessWindowStyle.Normal
>
> myProcess.Start()
> AddHandler myProcess.Exited, AddressOf MyProcessExited
> ' Set 'EnableRaisingEvents' to true, to raise
> 'Exited' event when process is terminated.
> myProcess.EnableRaisingEvents = True
>
> Dim i As Integer
>
> While m_iViewerHandle = 0 Or i < 10
> m_iViewerHandle = FindWindow(vbNullString, "VIEW")
> i = i + 1
> End While
>
> m_iHandle = m_iViewerHandle
> Return m_iHandle
> ......
>
> With this code, as long as I am in my While.... loop, the process I start is
> freeze and my all application gets "No responding status".
>
> To sumurize the situation I need to:
> - strart my exe process without locking my my application
> - retrive the correct window handle
>
>
> Thanks to help me to solve my issue.
> regards
> CALDERARA Serge

Jul 21 '05 #6
I will give a try, but then one important point is that, when the process is
properly launched, I need to retrive the handle of the displayed window...

If I start as a new thread, how can my main application is infromed that my
process window is ready. How can my new created thread can return the window
handle to my main applciatiom?

Thanks for your help

"JWhitted" wrote:
It sounds like the process is starting on the same thread. Might be good to
start the process on another thread and let it invoke a callback method when
it is ready. This will prevent your primary thread from hanging.

The following example is in C#.
1. Make sure the namespace System.Threading is imported:
using System.Threading;

2. Instead of starting the process, queue the process into the thread pool.
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));

3. The ThreadProc procedure should be declared, which actually starts the
process on the new thread.
private void ThreadProc(object stateInfo)
{
// Start the process here.
// Whenever the process is finished, it can execute another method
// which continues where this leaves off.
}

Hope that helps.

--
Jason Whitted

"serge calderara" wrote:
Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=================================================

......
Dim myProcessStartInfo As New ProcessStartInfo(m_sIntouchInstallPath &
"\view.exe")
myProcessStartInfo.UseShellExecute = False
myProcess.StartInfo = myProcessStartInfo
myProcess.StartInfo.WindowStyle =
ProcessWindowStyle.Normal

myProcess.Start()
AddHandler myProcess.Exited, AddressOf MyProcessExited
' Set 'EnableRaisingEvents' to true, to raise
'Exited' event when process is terminated.
myProcess.EnableRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNullString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge

Jul 21 '05 #7
An other question I got is:

How my main thread will know that the process has finished started and it
interface is open?

In the other way, how can the new thread informed the maion frame about its
status and its main windows handle ? can the new thread raise an event and
tha main thread is registered to that events?

thanks for your help
serge

"JWhitted" wrote:
It sounds like the process is starting on the same thread. Might be good to
start the process on another thread and let it invoke a callback method when
it is ready. This will prevent your primary thread from hanging.

The following example is in C#.
1. Make sure the namespace System.Threading is imported:
using System.Threading;

2. Instead of starting the process, queue the process into the thread pool.
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));

3. The ThreadProc procedure should be declared, which actually starts the
process on the new thread.
private void ThreadProc(object stateInfo)
{
// Start the process here.
// Whenever the process is finished, it can execute another method
// which continues where this leaves off.
}

Hope that helps.

--
Jason Whitted

"serge calderara" wrote:
Dear all,

I have an application which is suppose to start another executable process.
As soon as that process is running, I need to retrive its handle. The
problem of the particular process I am starting is that it has a welcome
window first which gets displayed and then the real windows after a while,in
other words it means that the process name is the same, but the handle I need
to retrive is the one from the final window and not the welome window.

So in real that means that from my main application I need to wait for a
while that the whol process started is really finishe to load befor getting
the real handle I am interresting on. The problem I get if I set a kind of
small loop in my main application is that the process I try to start is
freezed as long as I remain in my main application loop.

In other words how can I start my process, asynchronously from my main
application and then after a while try to retrive its handle ??

For you infor I use the follwoing code to starting it:
=================================================

......
Dim myProcessStartInfo As New ProcessStartInfo(m_sIntouchInstallPath &
"\view.exe")
myProcessStartInfo.UseShellExecute = False
myProcess.StartInfo = myProcessStartInfo
myProcess.StartInfo.WindowStyle =
ProcessWindowStyle.Normal

myProcess.Start()
AddHandler myProcess.Exited, AddressOf MyProcessExited
' Set 'EnableRaisingEvents' to true, to raise
'Exited' event when process is terminated.
myProcess.EnableRaisingEvents = True

Dim i As Integer

While m_iViewerHandle = 0 Or i < 10
m_iViewerHandle = FindWindow(vbNullString, "VIEW")
i = i + 1
End While

m_iHandle = m_iViewerHandle
Return m_iHandle
......

With this code, as long as I am in my While.... loop, the process I start is
freeze and my all application gets "No responding status".

To sumurize the situation I need to:
- strart my exe process without locking my my application
- retrive the correct window handle
Thanks to help me to solve my issue.
regards
CALDERARA Serge

Jul 21 '05 #8
I wrote a little Console App that should show you what I'm talking about.
This app will start a process in another thread, which launches Internet
Explorer (you might need to change the path to get this to work on your box).
It then pauses for a few seconds and then calls a callback function which
accepts the handle of the window as a parameter. Once the handle of the
window is received, the IE window is flashed and then closed (along with the
process).

The only additional concern I can forsee you having is using this
functionality as part of a windows app instead of a console app. In that
case, instead of calling the callback function directly, you might have to
create a callback delegegate method and invoke it using the Form's Invoke
method. This will be necessary because all GUI modifications should happen
on the primary thread of the window. Any attempt to modify GUI elements from
a child thread usually results in an exception being thrown.

Hope that helps.

--
Jason Whitted

#########################
Class1.cs
#########################
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;

namespace Testing
{
public class Class1
{
private Process proc;

public Class1()
{
Console.WriteLine("Class1 Constructor called");
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
}

public void ThreadProc(object stateInfo)
{
Console.WriteLine("Starting Process");
proc = Process.Start(@"C:\Program Files\Internet
Explorer\IExplore.exe", "http://www.microsoft.com");
Console.Write("Pausing: ");
for(int x=5; x>0; x--)
{
Console.Write(" " + x);
Thread.Sleep(1000);
}
Console.WriteLine();
Callback(proc.MainWindowHandle);

}

public void Callback(IntPtr handle)
{
Console.WriteLine("Callback called (handle=" + handle.ToString()
+ ")");
Thread.Sleep(1000);
Console.WriteLine("Flashing window");
for(int x=0; x<20; x++)
{
FlashWindow(handle, x%2);
Thread.Sleep(50);
}
Console.WriteLine("Closing Window Process");
proc.CloseMainWindow();
Console.WriteLine("Closing Process");
proc.Close();
Console.WriteLine("Done");
}

[DllImport("user32")]
public static extern int FlashWindow(IntPtr handle, int bInvert);

public static void Main(string[] args)
{
new Class1();
Console.ReadLine();
}
}
}

Jul 21 '05 #9
Thnaks for your sample appliction...
It helps me a lot to understand what you mean, but sorry to disturbed you
again, I still have some weal points on really understanding...

1 - CALLBACK term
===============
In your sample in the start process thread you call the function named
CALLBACK to retrive the window handle and close it after a while.
What I am confuse here is the term CALLBACK, because if I name your function
an other manner it works too, so does the CALLBACL terms you are mentionning
here is this wierd and strange system behaviour that developper like me do
not reaal understand. could you details what you means here by callback...

And I do not catch what you means also by Delegates call back events, I
never used that..

I am nearlyy close to the end but I like to do things that I am clearly
understanding

2 Getting handl back toi main applcation
==========================
No problem for doing this in my WIndows applicatin, the only point is that
after my process is launch, I should be able to close it or show it if it has
been minimized and the only way is that my main application should retrive
the window handle.

3 Show the created process window application
Another point that come to my mind.lets say that the process has been
started properly and its main windows application is running. Now my user is
minimizing the windows whcih goes down to taskbar. I should be able from my
main application to show that window in normal mode in case it is called
again has it is already exist. Under VB 5 for instance i will use the
FindWindow and ShowWindow function. How to do then with this new thread to
call window in front.
If I call the same procedure that was callin it initially to start the
process, it will creat an other thred instance, and I would need in fact to
just call the one which have been launched..

Thnaks for your help

Serge

"JWhitted" wrote:
I wrote a little Console App that should show you what I'm talking about.
This app will start a process in another thread, which launches Internet
Explorer (you might need to change the path to get this to work on your box).
It then pauses for a few seconds and then calls a callback function which
accepts the handle of the window as a parameter. Once the handle of the
window is received, the IE window is flashed and then closed (along with the
process).

The only additional concern I can forsee you having is using this
functionality as part of a windows app instead of a console app. In that
case, instead of calling the callback function directly, you might have to
create a callback delegegate method and invoke it using the Form's Invoke
method. This will be necessary because all GUI modifications should happen
on the primary thread of the window. Any attempt to modify GUI elements from
a child thread usually results in an exception being thrown.

Hope that helps.

--
Jason Whitted

#########################
Class1.cs
#########################
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;

namespace Testing
{
public class Class1
{
private Process proc;

public Class1()
{
Console.WriteLine("Class1 Constructor called");
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
}

public void ThreadProc(object stateInfo)
{
Console.WriteLine("Starting Process");
proc = Process.Start(@"C:\Program Files\Internet
Explorer\IExplore.exe", "http://www.microsoft.com");
Console.Write("Pausing: ");
for(int x=5; x>0; x--)
{
Console.Write(" " + x);
Thread.Sleep(1000);
}
Console.WriteLine();
Callback(proc.MainWindowHandle);

}

public void Callback(IntPtr handle)
{
Console.WriteLine("Callback called (handle=" + handle.ToString()
+ ")");
Thread.Sleep(1000);
Console.WriteLine("Flashing window");
for(int x=0; x<20; x++)
{
FlashWindow(handle, x%2);
Thread.Sleep(50);
}
Console.WriteLine("Closing Window Process");
proc.CloseMainWindow();
Console.WriteLine("Closing Process");
proc.Close();
Console.WriteLine("Done");
}

[DllImport("user32")]
public static extern int FlashWindow(IntPtr handle, int bInvert);

public static void Main(string[] args)
{
new Class1();
Console.ReadLine();
}
}
}

Jul 21 '05 #10
hello,

I have implemented your suggested way on starting a process into an external
thread. Thats wiorks ok in my windows applciation.

Problem that I noticed now is that previously my application was register to
the Exited event generated by the launch process and now I cannot catch
anymore that event as it is generated in a different thread.

I think that it joins a bit my previous post in the sens that how to catch
from my main application Events generated from an other thread

thnask for your help
serge

"JWhitted" wrote:
I wrote a little Console App that should show you what I'm talking about.
This app will start a process in another thread, which launches Internet
Explorer (you might need to change the path to get this to work on your box).
It then pauses for a few seconds and then calls a callback function which
accepts the handle of the window as a parameter. Once the handle of the
window is received, the IE window is flashed and then closed (along with the
process).

The only additional concern I can forsee you having is using this
functionality as part of a windows app instead of a console app. In that
case, instead of calling the callback function directly, you might have to
create a callback delegegate method and invoke it using the Form's Invoke
method. This will be necessary because all GUI modifications should happen
on the primary thread of the window. Any attempt to modify GUI elements from
a child thread usually results in an exception being thrown.

Hope that helps.

--
Jason Whitted

#########################
Class1.cs
#########################
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;

namespace Testing
{
public class Class1
{
private Process proc;

public Class1()
{
Console.WriteLine("Class1 Constructor called");
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
}

public void ThreadProc(object stateInfo)
{
Console.WriteLine("Starting Process");
proc = Process.Start(@"C:\Program Files\Internet
Explorer\IExplore.exe", "http://www.microsoft.com");
Console.Write("Pausing: ");
for(int x=5; x>0; x--)
{
Console.Write(" " + x);
Thread.Sleep(1000);
}
Console.WriteLine();
Callback(proc.MainWindowHandle);

}

public void Callback(IntPtr handle)
{
Console.WriteLine("Callback called (handle=" + handle.ToString()
+ ")");
Thread.Sleep(1000);
Console.WriteLine("Flashing window");
for(int x=0; x<20; x++)
{
FlashWindow(handle, x%2);
Thread.Sleep(50);
}
Console.WriteLine("Closing Window Process");
proc.CloseMainWindow();
Console.WriteLine("Closing Process");
proc.Close();
Console.WriteLine("Done");
}

[DllImport("user32")]
public static extern int FlashWindow(IntPtr handle, int bInvert);

public static void Main(string[] args)
{
new Class1();
Console.ReadLine();
}
}
}

Jul 21 '05 #11
hello again

so soirry to disturb you, but as you may know you build your knowledge with
the knowledge of others.
:-)

I point out a document on how to use Delegate events, I will try to
implement it for my case.

In case somethis still dark for me do you might if I conctact you here again

regards and thanks
serge

"JWhitted" wrote:
I wrote a little Console App that should show you what I'm talking about.
This app will start a process in another thread, which launches Internet
Explorer (you might need to change the path to get this to work on your box).
It then pauses for a few seconds and then calls a callback function which
accepts the handle of the window as a parameter. Once the handle of the
window is received, the IE window is flashed and then closed (along with the
process).

The only additional concern I can forsee you having is using this
functionality as part of a windows app instead of a console app. In that
case, instead of calling the callback function directly, you might have to
create a callback delegegate method and invoke it using the Form's Invoke
method. This will be necessary because all GUI modifications should happen
on the primary thread of the window. Any attempt to modify GUI elements from
a child thread usually results in an exception being thrown.

Hope that helps.

--
Jason Whitted

#########################
Class1.cs
#########################
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;

namespace Testing
{
public class Class1
{
private Process proc;

public Class1()
{
Console.WriteLine("Class1 Constructor called");
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
}

public void ThreadProc(object stateInfo)
{
Console.WriteLine("Starting Process");
proc = Process.Start(@"C:\Program Files\Internet
Explorer\IExplore.exe", "http://www.microsoft.com");
Console.Write("Pausing: ");
for(int x=5; x>0; x--)
{
Console.Write(" " + x);
Thread.Sleep(1000);
}
Console.WriteLine();
Callback(proc.MainWindowHandle);

}

public void Callback(IntPtr handle)
{
Console.WriteLine("Callback called (handle=" + handle.ToString()
+ ")");
Thread.Sleep(1000);
Console.WriteLine("Flashing window");
for(int x=0; x<20; x++)
{
FlashWindow(handle, x%2);
Thread.Sleep(50);
}
Console.WriteLine("Closing Window Process");
proc.CloseMainWindow();
Console.WriteLine("Closing Process");
proc.Close();
Console.WriteLine("Done");
}

[DllImport("user32")]
public static extern int FlashWindow(IntPtr handle, int bInvert);

public static void Main(string[] args)
{
new Class1();
Console.ReadLine();
}
}
}

Jul 21 '05 #12
Hello gain,

Dear all,

The new problem I met when implementing Delegate to my application is that
my application is creating dynamic reference to existing plug-ins and the
only way I communicate with my plug in and my applciation is a common
Interface that I have defined.

Now, how can I defined my delegate type in my Interface and in my
application to be able to work correctly ?

Thnaks for your help
Serge

"JWhitted" wrote:
I wrote a little Console App that should show you what I'm talking about.
This app will start a process in another thread, which launches Internet
Explorer (you might need to change the path to get this to work on your box).
It then pauses for a few seconds and then calls a callback function which
accepts the handle of the window as a parameter. Once the handle of the
window is received, the IE window is flashed and then closed (along with the
process).

The only additional concern I can forsee you having is using this
functionality as part of a windows app instead of a console app. In that
case, instead of calling the callback function directly, you might have to
create a callback delegegate method and invoke it using the Form's Invoke
method. This will be necessary because all GUI modifications should happen
on the primary thread of the window. Any attempt to modify GUI elements from
a child thread usually results in an exception being thrown.

Hope that helps.

--
Jason Whitted

#########################
Class1.cs
#########################
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;

namespace Testing
{
public class Class1
{
private Process proc;

public Class1()
{
Console.WriteLine("Class1 Constructor called");
ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc));
}

public void ThreadProc(object stateInfo)
{
Console.WriteLine("Starting Process");
proc = Process.Start(@"C:\Program Files\Internet
Explorer\IExplore.exe", "http://www.microsoft.com");
Console.Write("Pausing: ");
for(int x=5; x>0; x--)
{
Console.Write(" " + x);
Thread.Sleep(1000);
}
Console.WriteLine();
Callback(proc.MainWindowHandle);

}

public void Callback(IntPtr handle)
{
Console.WriteLine("Callback called (handle=" + handle.ToString()
+ ")");
Thread.Sleep(1000);
Console.WriteLine("Flashing window");
for(int x=0; x<20; x++)
{
FlashWindow(handle, x%2);
Thread.Sleep(50);
}
Console.WriteLine("Closing Window Process");
proc.CloseMainWindow();
Console.WriteLine("Closing Process");
proc.Close();
Console.WriteLine("Done");
}

[DllImport("user32")]
public static extern int FlashWindow(IntPtr handle, int bInvert);

public static void Main(string[] args)
{
new Class1();
Console.ReadLine();
}
}
}

Jul 21 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ChrisWinterscheid | last post by:
We are running DB2 8.1 on AIX 5.2. DB2level shows: DB21085I Instance "db2inst1" uses "32" bits and DB2 code release "SQL08016" with level identifier "02070106". Informational tokens are "DB2...
0
by: calderara serge | last post by:
Dear All, I am building an application with VB.Net that is starting an external process from my application code by using the process object. The problem I get is that the application that I...
12
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am...
0
by: graciezzzzz | last post by:
Hi all, I create a Web Service project called 'eSelectService' and another Class Library project called 'MonerisVO', and a Windows Form project called 'maps' as well. The reason why I need...
4
by: Phil Mc | last post by:
Say for example you have a application running on a windows 2003 server (that is on server, not from). This application needs to start child applications (must be stand alone console applications),...
3
by: zxo102 | last post by:
Hi there, I have a python application (many python scripts) and I start the application like this python myServer.py start in window. It is running in dos window. Now I would like to put it...
1
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req):...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
5
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name?...
0
isladogs
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.