Multithreading

  • Thread starter Thread starter Michael C
  • Start date Start date
M

Michael C

Hello

Can someone please tell me what I'm doing wrong? I'm writing an application
that should be using callbacks to perform asynchronous calls to the Win32
API. Problem is it never reaches my callback function. Any feedback is
appreciated. Also, any references to websites with examples of .NET async
multithreading would be appreciated. Thanks in advance.

public serverInfo getSession(string servername)
{
serverInfo svInfo;
Object stateObj = new Object();
delGetServer x = new delGetServer(getServer);
IAsyncResult ar = x.BeginInvoke(servername, out svInfo, new
AsyncCallback(finishedProc), stateObj);
return (svInfo);
}

public static void getServer(string servername, out serverInfo svInfo)
{
// performs Win32 API calls to get server info. on network
}

public delegate void delGetServer (string s1, out serverInfo svInfo);

public static void finishedProc(IAsyncResult ar)
{
serverInfo svInfo;
delGetServer temp = (delGetServer)ar.AsyncState;
temp.EndInvoke(out svInfo, ar);
}
 
Hi, Michael

Problem is that code is not complete. If you use asynch invoke like this one
[C#]
public IAsyncResult BeginInvoke(
object target,
object[] values,
AsyncCallback callback,
object asyncState
);then there are some differences in syntax. I would suggest to put tracers
in called methods to see process flow. Might happen your called delegate
 
Thanks. I'm new to multithreading in .NET. I know the Async Callback
function is not being called. What's a tracer?

Michael C

AlexS said:
Hi, Michael

Problem is that code is not complete. If you use asynch invoke like this one
[C#]
public IAsyncResult BeginInvoke(
object target,
object[] values,
AsyncCallback callback,
object asyncState
);then there are some differences in syntax. I would suggest to put tracers
in called methods to see process flow. Might happen your called delegate
message news:[email protected]...
Hello

Can someone please tell me what I'm doing wrong? I'm writing an application
that should be using callbacks to perform asynchronous calls to the Win32
API. Problem is it never reaches my callback function. Any feedback is
appreciated. Also, any references to websites with examples of .NET async
multithreading would be appreciated. Thanks in advance.

public serverInfo getSession(string servername)
{
serverInfo svInfo;
Object stateObj = new Object();
delGetServer x = new delGetServer(getServer);
IAsyncResult ar = x.BeginInvoke(servername, out svInfo, new
AsyncCallback(finishedProc), stateObj);
return (svInfo);
}

public static void getServer(string servername, out serverInfo svInfo)
{
// performs Win32 API calls to get server info. on network
}

public delegate void delGetServer (string s1, out serverInfo svInfo);

public static void finishedProc(IAsyncResult ar)
{
serverInfo svInfo;
delGetServer temp = (delGetServer)ar.AsyncState;
temp.EndInvoke(out svInfo, ar);
}
 
Michael,

tracer = Console.WriteLine or Debug/Trace calls.

delGetServer temp = (delGetServer)ar.AsyncState should be changed to
ar.AsyncDelegate. You try to get delegate from state, which doesn't work.
You can't see exception, because you don't have try/catch and execute on
another thread.

And I have slight suspicion that finishedProc is called once again by
EndInvoke. Check if EndInvokeCalled and IsCompleted too.

HTH
Alex

Michael C said:
Thanks. I'm new to multithreading in .NET. I know the Async Callback
function is not being called. What's a tracer?

Michael C

AlexS said:
Hi, Michael

Problem is that code is not complete. If you use asynch invoke like this one
[C#]
public IAsyncResult BeginInvoke(
object target,
object[] values,
AsyncCallback callback,
object asyncState
);then there are some differences in syntax. I would suggest to put tracers
in called methods to see process flow. Might happen your called delegate
message news:[email protected]...
Hello

Can someone please tell me what I'm doing wrong? I'm writing an application
that should be using callbacks to perform asynchronous calls to the Win32
API. Problem is it never reaches my callback function. Any feedback is
appreciated. Also, any references to websites with examples of .NET async
multithreading would be appreciated. Thanks in advance.

public serverInfo getSession(string servername)
{
serverInfo svInfo;
Object stateObj = new Object();
delGetServer x = new delGetServer(getServer);
IAsyncResult ar = x.BeginInvoke(servername, out svInfo, new
AsyncCallback(finishedProc), stateObj);
return (svInfo);
}

public static void getServer(string servername, out serverInfo svInfo)
{
// performs Win32 API calls to get server info. on network
}

public delegate void delGetServer (string s1, out serverInfo svInfo);

public static void finishedProc(IAsyncResult ar)
{
serverInfo svInfo;
delGetServer temp = (delGetServer)ar.AsyncState;
temp.EndInvoke(out svInfo, ar);
}
 
Thanks for the help. I finally got it working. Only one problem - not all
of my threads are being killed after they do their job. After returning
their info., I'm consistently stuck with 5 or 6 threads that haven't been
killed. Any way to kill all worker threads at once?

Thanks,
Michael C.

AlexS said:
Michael,

tracer = Console.WriteLine or Debug/Trace calls.

delGetServer temp = (delGetServer)ar.AsyncState should be changed to
ar.AsyncDelegate. You try to get delegate from state, which doesn't work.
You can't see exception, because you don't have try/catch and execute on
another thread.

And I have slight suspicion that finishedProc is called once again by
EndInvoke. Check if EndInvokeCalled and IsCompleted too.

HTH
Alex

Michael C said:
Thanks. I'm new to multithreading in .NET. I know the Async Callback
function is not being called. What's a tracer?

Michael C

AlexS said:
Hi, Michael

Problem is that code is not complete. If you use asynch invoke like
this
one
[C#]
public IAsyncResult BeginInvoke(
object target,
object[] values,
AsyncCallback callback,
object asyncState
);then there are some differences in syntax. I would suggest to put tracers
in called methods to see process flow. Might happen your called delegate
really doesn't return.HTHAlex"Michael C" <[email protected]>
wrote
in
message Hello

Can someone please tell me what I'm doing wrong? I'm writing an
application
that should be using callbacks to perform asynchronous calls to the Win32
API. Problem is it never reaches my callback function. Any
feedback
 
Michael,

what do you mean by killed?


Michael C said:
Thanks for the help. I finally got it working. Only one problem - not all
of my threads are being killed after they do their job. After returning
their info., I'm consistently stuck with 5 or 6 threads that haven't been
killed. Any way to kill all worker threads at once?

Thanks,
Michael C.

AlexS said:
Michael,

tracer = Console.WriteLine or Debug/Trace calls.

delGetServer temp = (delGetServer)ar.AsyncState should be changed to
ar.AsyncDelegate. You try to get delegate from state, which doesn't work.
You can't see exception, because you don't have try/catch and execute on
another thread.

And I have slight suspicion that finishedProc is called once again by
EndInvoke. Check if EndInvokeCalled and IsCompleted too.

HTH
Alex

Michael C said:
Thanks. I'm new to multithreading in .NET. I know the Async Callback
function is not being called. What's a tracer?

Michael C

Hi, Michael

Problem is that code is not complete. If you use asynch invoke like this
one
[C#]
public IAsyncResult BeginInvoke(
object target,
object[] values,
AsyncCallback callback,
object asyncState
);then there are some differences in syntax. I would suggest to put
tracers
in called methods to see process flow. Might happen your called delegate
in
message Hello

Can someone please tell me what I'm doing wrong? I'm writing an
application
that should be using callbacks to perform asynchronous calls to the
Win32
API. Problem is it never reaches my callback function. Any
feedback
is
appreciated. Also, any references to websites with examples of ..NET
async
multithreading would be appreciated. Thanks in advance.

public serverInfo getSession(string servername)
{
serverInfo svInfo;
Object stateObj = new Object();
delGetServer x = new delGetServer(getServer);
IAsyncResult ar = x.BeginInvoke(servername, out svInfo, new
AsyncCallback(finishedProc), stateObj);
return (svInfo);
}

public static void getServer(string servername, out serverInfo svInfo)
{
// performs Win32 API calls to get server info. on network
}

public delegate void delGetServer (string s1, out serverInfo svInfo);

public static void finishedProc(IAsyncResult ar)
{
serverInfo svInfo;
delGetServer temp = (delGetServer)ar.AsyncState;
temp.EndInvoke(out svInfo, ar);
}
 
I think I might have solved this one. I think I was recreating new
delegates when I was trying to kill the previous ones (i.e., stop them from
running). Sorry about the lingo - I forgot killing threads is what you do
on UN*X. I was just wondering if there was a way to force all the worker
threads to stop running at one shot, through a single instruction?

Thanks,
Michael C.

AlexS said:
Michael,

what do you mean by killed?


Michael C said:
Thanks for the help. I finally got it working. Only one problem - not all
of my threads are being killed after they do their job. After returning
their info., I'm consistently stuck with 5 or 6 threads that haven't been
killed. Any way to kill all worker threads at once?

Thanks,
Michael C.

AlexS said:
Michael,

tracer = Console.WriteLine or Debug/Trace calls.

delGetServer temp = (delGetServer)ar.AsyncState should be changed to
ar.AsyncDelegate. You try to get delegate from state, which doesn't work.
You can't see exception, because you don't have try/catch and execute on
another thread.

And I have slight suspicion that finishedProc is called once again by
EndInvoke. Check if EndInvokeCalled and IsCompleted too.

HTH
Alex

Thanks. I'm new to multithreading in .NET. I know the Async Callback
function is not being called. What's a tracer?

Michael C

Hi, Michael

Problem is that code is not complete. If you use asynch invoke
like
this
one
[C#]
public IAsyncResult BeginInvoke(
object target,
object[] values,
AsyncCallback callback,
object asyncState
);then there are some differences in syntax. I would suggest to put
tracers
in called methods to see process flow. Might happen your called delegate
in
message Hello

Can someone please tell me what I'm doing wrong? I'm writing an
application
that should be using callbacks to perform asynchronous calls to the
Win32
API. Problem is it never reaches my callback function. Any feedback
is
appreciated. Also, any references to websites with examples of .NET
async
multithreading would be appreciated. Thanks in advance.

public serverInfo getSession(string servername)
{
serverInfo svInfo;
Object stateObj = new Object();
delGetServer x = new delGetServer(getServer);
IAsyncResult ar = x.BeginInvoke(servername, out svInfo, new
AsyncCallback(finishedProc), stateObj);
return (svInfo);
}

public static void getServer(string servername, out serverInfo svInfo)
{
// performs Win32 API calls to get server info. on network
}

public delegate void delGetServer (string s1, out serverInfo svInfo);

public static void finishedProc(IAsyncResult ar)
{
serverInfo svInfo;
delGetServer temp = (delGetServer)ar.AsyncState;
temp.EndInvoke(out svInfo, ar);
}
 
Back
Top