473,387 Members | 1,520 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,387 software developers and data experts.

confusion regarding threading

Hi all,

I have one confusion regarding threading in windows service which is
developed in c#.

What i am doing is on 'onstart' event i am starting one thread.

In thread procedure i am processing some URL's asynchronously.

Say in thread procedure for validating url through webrequest i am
calling beginwebrequest for procesing 5 urls at a time.

Does it means my thread is spawn into 5 threads. Means invoking
webrquest asynchronouly create new thread? And if yes does it create
thread in threadpool.

Secondly in beginwebrequest i am passing one callback fuction whcih
needs to get invoke after processing completed. This callback i am
handling in outer thread.

After after this process is over i am enabling one timer which is again
doing same things on its elapsed event. Means start processing of 5
webrequest asynchronously.

Can some one tell me is anything wrong in this code.

Becuase this code is hanging suddenly after working properly for say
3-4 times.

Please correct me if i am wrong.

thanks in advance.

Jul 27 '06 #1
3 1688
hi,
Yes calling Any 'beginAsync' method creates a new thread to execute on.
As for it being created in the ThreadPool - no it is not. What I think you
are missing is the fact that you should use the Async callback to maybe call
the remainding urls. The hang does sound like you have a thread locking
problem, it has not been released. But I think a snippet of the code would
help.
James Jenkins
http://www.tamarsolutions.co.uk

"archana" <tr**************@yahoo.comwrote in message
news:11********************@h48g2000cwc.googlegrou ps.com...
Hi all,

I have one confusion regarding threading in windows service which is
developed in c#.

What i am doing is on 'onstart' event i am starting one thread.

In thread procedure i am processing some URL's asynchronously.

Say in thread procedure for validating url through webrequest i am
calling beginwebrequest for procesing 5 urls at a time.

Does it means my thread is spawn into 5 threads. Means invoking
webrquest asynchronouly create new thread? And if yes does it create
thread in threadpool.

Secondly in beginwebrequest i am passing one callback fuction whcih
needs to get invoke after processing completed. This callback i am
handling in outer thread.

After after this process is over i am enabling one timer which is again
doing same things on its elapsed event. Means start processing of 5
webrequest asynchronously.

Can some one tell me is anything wrong in this code.

Becuase this code is hanging suddenly after working properly for say
3-4 times.

Please correct me if i am wrong.

thanks in advance.

Jul 27 '06 #2

archana wrote:
Hi all,

I have one confusion regarding threading in windows service which is
developed in c#.

What i am doing is on 'onstart' event i am starting one thread.

In thread procedure i am processing some URL's asynchronously.

Say in thread procedure for validating url through webrequest i am
calling beginwebrequest for procesing 5 urls at a time.

Does it means my thread is spawn into 5 threads. Means invoking
webrquest asynchronouly create new thread? And if yes does it create
thread in threadpool.
I'm pretty sure it won't spawn 5 new threads. It's more likely that
those requests are placed in the ThreadPool, use IO completion ports,
or something of the like. Threads are not necessarily created when
queueing work items into the ThreadPool anyway. If an idle thread
exists in the pool then the work item will likely be dispatched to that
thread.
Secondly in beginwebrequest i am passing one callback fuction whcih
needs to get invoke after processing completed. This callback i am
handling in outer thread.
That's impossible unless you are marshaling the execution of the
callback onto the outer thread. Callbacks from asynchronous operations
(especially those involing the BeginXXX and EndXXX pattern) are
generally executed on the same thread that processed the operation.
After after this process is over i am enabling one timer which is again
doing same things on its elapsed event. Means start processing of 5
webrequest asynchronously.
Which timer are you using (there are 3 in the base class library)?
Specifically, when and where are you enabling the timer? Is it
possible that the you're kicking off asynchronous requests faster than
they are completing?
>
Can some one tell me is anything wrong in this code.

Becuase this code is hanging suddenly after working properly for say
3-4 times.
Can you post some code?
Please correct me if i am wrong.

thanks in advance.
Jul 27 '06 #3
Hi,

See inline
What i am doing is on 'onstart' event i am starting one thread.
The way to go.
In thread procedure i am processing some URL's asynchronously.
How many URLs are you doing it the same time? IMO this is the part where
the problem may be, depending of how you do it. Post this piece of the code.

Does it means my thread is spawn into 5 threads. Means invoking
webrquest asynchronouly create new thread? And if yes does it create
thread in threadpool.
Yes, each Async will create a new thread, don't really remember if it gets
them from threadpool , a search in MSDN will tell though.
Secondly in beginwebrequest i am passing one callback fuction whcih
needs to get invoke after processing completed. This callback i am
handling in outer thread.
Also a good candidate for a race condition, post the code , or just wrap the
entire method in a critical section.
After after this process is over i am enabling one timer which is again
doing same things on its elapsed event. Means start processing of 5
webrequest asynchronously.
It's possible the some of the previous one are still running so you have to
take that into account.

post some code .
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jul 27 '06 #4

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

Similar topics

6
by: akash shetty | last post by:
hi, im developing a code which requires searching a large database(bioological) for certain patterns.the size of the file is 3.5GB . the search pattern is a ten letter string.the database...
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
4
by: trialproduct2004 | last post by:
Hi all i am having application in C#. here what i want it to update one datagrid depending on particular value. I want to start minimum of 5 threads at a time and all these threads are updating...
1
by: archana | last post by:
Hi all, I am having one confusion regarding changing cursor to wait cursor I am providing auto refreshing facility for listview using timer. So what i am doing is when auto refreshing is in...
4
by: archana | last post by:
Hi all, I am having one confusion regarding invoking web method of web service asychronously through windows applicaiton. What i am doing is i am having one long runing web method whose one...
10
by: =?Utf-8?B?UnVkeQ==?= | last post by:
Hello All! So I'm trying to figure out threading. I got the basic idea of how to start new threads, but getting a little lost with the form thing. I understand the that form runs a single...
2
by: archana | last post by:
Hi all, I am having one confusion regarding hashtable. I am having function in which i am passing hashtable as reference. In function i am creating one hashtable which is local to that...
11
by: ohmmega | last post by:
hello world. i would like to implement a class with a timer, witch informs me every second about it's tick. the code works already, but i would like to change a thing (or more). <code> //at...
6
by: George Sakkis | last post by:
I'm baffled with a situation that involves: 1) an instance of some class that defines __del__, 2) a thread which is created, started and referenced by that instance, and 3) a weakref proxy to the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...

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.