473,385 Members | 1,555 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.

Multithreading

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);
}
Nov 16 '05 #1
6 2279
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" <mi*******@optonline.net> wrote in
message news:hZ*********************@news4.srv.hcvlny.cv.n et...
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);
}

Nov 16 '05 #2
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" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:Ok**************@TK2MSFTNGP09.phx.gbl...
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" <mi*******@optonline.net> wrote in message news:hZ*********************@news4.srv.hcvlny.cv.n et...
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);
}


Nov 16 '05 #3
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" <mi*******@optonline.net> wrote in message
news:Ju*********************@news4.srv.hcvlny.cv.n et...
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" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:Ok**************@TK2MSFTNGP09.phx.gbl...
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" <mi*******@optonline.net> wrote

in
message news:hZ*********************@news4.srv.hcvlny.cv.n et...
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);
}



Nov 16 '05 #4
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" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
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" <mi*******@optonline.net> wrote in message
news:Ju*********************@news4.srv.hcvlny.cv.n et...
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" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:Ok**************@TK2MSFTNGP09.phx.gbl...
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" <mi*******@optonline.net> wrote
in
message news:hZ*********************@news4.srv.hcvlny.cv.n et...
> 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);
> }
>
>



Nov 16 '05 #5
Michael,

what do you mean by killed?
"Michael C" <mi*******@optonline.net> wrote in message
news:IN*********************@news4.srv.hcvlny.cv.n et...
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" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
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" <mi*******@optonline.net> wrote in message
news:Ju*********************@news4.srv.hcvlny.cv.n et...
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" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:Ok**************@TK2MSFTNGP09.phx.gbl...
> 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" <mi*******@optonline.net> wrote in
> message news:hZ*********************@news4.srv.hcvlny.cv.n et...
> > 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);
> > }
> >
> >
>
>



Nov 16 '05 #6
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" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Michael,

what do you mean by killed?
"Michael C" <mi*******@optonline.net> wrote in message
news:IN*********************@news4.srv.hcvlny.cv.n et...
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" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
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" <mi*******@optonline.net> wrote in message
news:Ju*********************@news4.srv.hcvlny.cv.n et...
> 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" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
> news:Ok**************@TK2MSFTNGP09.phx.gbl...
> > 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" <mi*******@optonline.net>

wrote
> in
> > message news:hZ*********************@news4.srv.hcvlny.cv.n et...
> > > 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);
> > > }
> > >
> > >
> >
> >
>
>



Nov 16 '05 #7

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

Similar topics

1
by: dixp | last post by:
I'm new to writing multithreaded apps and I have a design question. I have a winforms app and a class which has a method that does processing which is time intensive. I want the user to be able...
47
by: mihai | last post by:
What does the standard say about those two? Is any assurance that the use of STL is thread safe? Have a nice day, Mihai.
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
5
by: sarge | last post by:
I would like to know how to perform simple multithreading. I had created a simple form to test out if I was multithreading properly, but got buggy results. Sometime the whole thig would lock up...
9
by: tommy | last post by:
hi, i have found a example for multithreading and asp.net http://www.fawcette.com/vsm/2002_11/magazine/features/chester/ i want to speed up my website ... if my website is starting, they...
2
by: Rich | last post by:
Hello, I have set up a multithreading routine in a Test VB.net proj, and it appears to be working OK in debug mode and I am not using synchronization. Multithreading is a new thing for me, and...
55
by: Sam | last post by:
Hi, I have a serious issue using multithreading. A sample application showing my issue can be downloaded here: http://graphicsxp.free.fr/WindowsApplication11.zip The problem is that I need to...
5
by: sandy82 | last post by:
Whats actuallly multithreading is ... and how threading and multithreading differ . Can any1 guide how multithreading is used on the Web .. i mean a practical scenario in which u use...
2
by: Pradnya Patil | last post by:
hi , I am trying to draw ' html div-tag ' on the screen which will resemble a rectangle through vb.net code. I want it to be drawn faster...so I introduced multithreading using Threadpool. I...
7
by: Ray | last post by:
Hello, Greetings! I'm looking for a solid C++ multithreading book. Can you recommend one? I don't think I've seen a multithreading C++ book that everybody thinks is good (like Effective C++ or...
0
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.