473,804 Members | 3,383 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1708
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.comwro te in message
news:11******** ************@h4 8g2000cwc.googl egroups.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
2245
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 consists of paragraphs. the code ive developed searches the data paragraphwise. (using xreadlines). but this takes an awful amt of time.(abt 7 mins) is there anyway to speed this up.
8
8221
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 party COM component that takes about 5 seconds to run one of its functions (Network IO bound call). Since I dont want my GUI to freeze
4
1325
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 datagrid in their thread proceudre. What i want is whenever 5 threads are running as soon as one thread finish its execution i want to asssing new thread proceudre to that thread. Can some one tell me how to do it?
1
2625
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 progress i am changing cursor to hour glass to indicate user that application is busy in background processing.
4
1401
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 way attribute is set as i don't want any return value from that method. What i observered is when my window application start calling web method asynchronoysly
10
1310
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 thread, and can't start a new thread from an object within a form. So, I have 8 pictureboxes on a form. The pictureboxes have, well, picture images in them. So when the form loads, they load up one at a time. So I'm thinking, start a thread for...
2
3881
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 function. Then i am setting this hash table to hashtable which i am passing as ref. So my question is how scope is mention when i am assigning local
11
1834
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 the moment i initialize the object with the constructor: public myClass(System.Timers.ElapsedEventHandler CallMeBack) {
6
2878
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 instance that is passed to the thread instead of 'self', to prevent a cyclic reference. This probably sounds like gibberish so here's a simplified example: ==========================================
0
9705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9575
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
10564
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
10320
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...
1
10308
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10073
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
7609
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
6846
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.