473,779 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(stri ng servername)
{
serverInfo svInfo;
Object stateObj = new Object();
delGetServer x = new delGetServer(ge tServer);
IAsyncResult ar = x.BeginInvoke(s ervername, out svInfo, new
AsyncCallback(f inishedProc), stateObj);
return (svInfo);
}

public static void getServer(strin g 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(IA syncResult ar)
{
serverInfo svInfo;
delGetServer temp = (delGetServer)a r.AsyncState;
temp.EndInvoke( out svInfo, ar);
}
Nov 16 '05 #1
6 2316
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*******@opto nline.net> wrote in
message news:hZ******** *************@n ews4.srv.hcvlny .cv.net...
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(stri ng servername)
{
serverInfo svInfo;
Object stateObj = new Object();
delGetServer x = new delGetServer(ge tServer);
IAsyncResult ar = x.BeginInvoke(s ervername, out svInfo, new
AsyncCallback(f inishedProc), stateObj);
return (svInfo);
}

public static void getServer(strin g 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(IA syncResult ar)
{
serverInfo svInfo;
delGetServer temp = (delGetServer)a r.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***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:Ok******** ******@TK2MSFTN GP09.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*******@opto nline.net> wrote in message news:hZ******** *************@n ews4.srv.hcvlny .cv.net...
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(stri ng servername)
{
serverInfo svInfo;
Object stateObj = new Object();
delGetServer x = new delGetServer(ge tServer);
IAsyncResult ar = x.BeginInvoke(s ervername, out svInfo, new
AsyncCallback(f inishedProc), stateObj);
return (svInfo);
}

public static void getServer(strin g 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(IA syncResult ar)
{
serverInfo svInfo;
delGetServer temp = (delGetServer)a r.AsyncState;
temp.EndInvoke( out svInfo, ar);
}


Nov 16 '05 #3
Michael,

tracer = Console.WriteLi ne or Debug/Trace calls.

delGetServer temp = (delGetServer)a r.AsyncState should be changed to
ar.AsyncDelegat e. 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*******@opto nline.net> wrote in message
news:Ju******** *************@n ews4.srv.hcvlny .cv.net...
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***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:Ok******** ******@TK2MSFTN GP09.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*******@opto nline.net> wrote

in
message news:hZ******** *************@n ews4.srv.hcvlny .cv.net...
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(stri ng servername)
{
serverInfo svInfo;
Object stateObj = new Object();
delGetServer x = new delGetServer(ge tServer);
IAsyncResult ar = x.BeginInvoke(s ervername, out svInfo, new
AsyncCallback(f inishedProc), stateObj);
return (svInfo);
}

public static void getServer(strin g 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(IA syncResult ar)
{
serverInfo svInfo;
delGetServer temp = (delGetServer)a r.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***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:eY******** ******@tk2msftn gp13.phx.gbl...
Michael,

tracer = Console.WriteLi ne or Debug/Trace calls.

delGetServer temp = (delGetServer)a r.AsyncState should be changed to
ar.AsyncDelegat e. 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*******@opto nline.net> wrote in message
news:Ju******** *************@n ews4.srv.hcvlny .cv.net...
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***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:Ok******** ******@TK2MSFTN GP09.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*******@opto nline.net> wrote
in
message news:hZ******** *************@n ews4.srv.hcvlny .cv.net...
> 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(stri ng servername)
> {
> serverInfo svInfo;
> Object stateObj = new Object();
> delGetServer x = new delGetServer(ge tServer);
> IAsyncResult ar = x.BeginInvoke(s ervername, out svInfo, new
> AsyncCallback(f inishedProc), stateObj);
> return (svInfo);
> }
>
> public static void getServer(strin g 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(IA syncResult ar)
> {
> serverInfo svInfo;
> delGetServer temp = (delGetServer)a r.AsyncState;
> temp.EndInvoke( out svInfo, ar);
> }
>
>



Nov 16 '05 #5
Michael,

what do you mean by killed?
"Michael C" <mi*******@opto nline.net> wrote in message
news:IN******** *************@n ews4.srv.hcvlny .cv.net...
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***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:eY******** ******@tk2msftn gp13.phx.gbl...
Michael,

tracer = Console.WriteLi ne or Debug/Trace calls.

delGetServer temp = (delGetServer)a r.AsyncState should be changed to
ar.AsyncDelegat e. 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*******@opto nline.net> wrote in message
news:Ju******** *************@n ews4.srv.hcvlny .cv.net...
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***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:Ok******** ******@TK2MSFTN GP09.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*******@opto nline.net> wrote in
> message news:hZ******** *************@n ews4.srv.hcvlny .cv.net...
> > 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(stri ng servername)
> > {
> > serverInfo svInfo;
> > Object stateObj = new Object();
> > delGetServer x = new delGetServer(ge tServer);
> > IAsyncResult ar = x.BeginInvoke(s ervername, out svInfo, new
> > AsyncCallback(f inishedProc), stateObj);
> > return (svInfo);
> > }
> >
> > public static void getServer(strin g 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(IA syncResult ar)
> > {
> > serverInfo svInfo;
> > delGetServer temp = (delGetServer)a r.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***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Michael,

what do you mean by killed?
"Michael C" <mi*******@opto nline.net> wrote in message
news:IN******** *************@n ews4.srv.hcvlny .cv.net...
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***********@ SPAMsympaticoPL EASE.ca> wrote in message
news:eY******** ******@tk2msftn gp13.phx.gbl...
Michael,

tracer = Console.WriteLi ne or Debug/Trace calls.

delGetServer temp = (delGetServer)a r.AsyncState should be changed to
ar.AsyncDelegat e. 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*******@opto nline.net> wrote in message
news:Ju******** *************@n ews4.srv.hcvlny .cv.net...
> 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***********@ SPAMsympaticoPL EASE.ca> wrote in message
> news:Ok******** ******@TK2MSFTN GP09.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*******@opto nline.net>

wrote
> in
> > message news:hZ******** *************@n ews4.srv.hcvlny .cv.net...
> > > 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(stri ng servername)
> > > {
> > > serverInfo svInfo;
> > > Object stateObj = new Object();
> > > delGetServer x = new delGetServer(ge tServer);
> > > IAsyncResult ar = x.BeginInvoke(s ervername, out svInfo, new
> > > AsyncCallback(f inishedProc), stateObj);
> > > return (svInfo);
> > > }
> > >
> > > public static void getServer(strin g 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(IA syncResult ar)
> > > {
> > > serverInfo svInfo;
> > > delGetServer temp = (delGetServer)a r.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
2054
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 to kick off the process and continue to work in the appliaction while getting progress updates and the ability to cancel. The method that seems easiest to me is this: The class exposes certain events for progress. Start, ProgressUpdate, and...
47
3756
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
8510
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
2139
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 when I got two threads going at the same time. What I have is two text boxes (textBox1 and textBox2) and four buttons(cmdStartThread1, cmdStartThread2, cmdStopThread1, cmdStopThread2)
9
2465
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 should build a database-connection and send a few sqls
2
2312
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 I just wanted to ask if I am missing anything based on the following scenario. My test app pulls data from a large external data source which has a table-like structure (but not rdbms - more
55
3328
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 call operations on Controls from a delegate, otherwise it does not work. However each time I've done an operation, I must update the progressbar and progresslabel, but this cannot be done in the delegate as it does not work.
5
2488
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 multithreading online using C# .
2
2267
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 divided the complete drawing into 3 parts..1st will be done by main thread and other two are done in these procedures - <1LongTimeTask <2LongTimeTask2 I have invoked the threads using below method. **************
7
16314
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 Exceptional C++, for example). Platform-specific (e.g.: Win32, POSIX) is OK, as long as it's good :) Thank you, Ray
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10302
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.