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

Help regarding monitor in Asynchronous call.

Hi all
i am having C# application which is processing 5 urls asychronously
using webrequest and webresponse classes.
What i want is as soon as any url request processing is completed i
want to decrement one counter and increment another count.
How should i do this in call back.
Do i need to use monitor so that no two calls can modified that counter
at the same time or without using any sychronous object i can do this.

Because when i am using monitor on counter, some time even if i have
statment like following.

system.monitor.enter(counter);
counter--;
system.monitor.exit(counter);

counter is not getting decremented.

can some one help me.

thanks in advance.

Nov 17 '05 #1
3 1427
It sounds as though you want your asynchronous process to fire an event back
to the controlling thread and inside the event handler use a lock statement
to synchronise access to the counters you wish to increment\decrement.

Look at events, delegates and event handlers on the MSDN site, this should
give you a start.

HTH

Ollie Riches
<tr**************@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Hi all
i am having C# application which is processing 5 urls asychronously
using webrequest and webresponse classes.
What i want is as soon as any url request processing is completed i
want to decrement one counter and increment another count.
How should i do this in call back.
Do i need to use monitor so that no two calls can modified that counter
at the same time or without using any sychronous object i can do this.

Because when i am using monitor on counter, some time even if i have
statment like following.

system.monitor.enter(counter);
counter--;
system.monitor.exit(counter);

counter is not getting decremented.

can some one help me.

thanks in advance.

Nov 17 '05 #2
hi
thanks for you.
I think you are not getting my problem completly.
I want to modify global counter in callback function itself.
My application is working properly for nearly 15 minutes and then its
hanging.
I am not getting why this is happening.

Any help will be appreciated.

thanks in advance.

Nov 17 '05 #3
yes and put a lock inside the callback function so that only one thread can
execute the code at a time:
public class1
{
private int someCounter;
private int someOtherCounter;

private object myLock = new object();

private void SomeCallbackFunction()
{
lock(myLock)
{
// this will now be synchronised - only one thread
will have access to code below at any one time

someCounter++;
someOtherCounter--;
}
}
}
HTH

Ollie Riches

<tr**************@yahoo.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
hi
thanks for you.
I think you are not getting my problem completly.
I want to modify global counter in callback function itself.
My application is working properly for nearly 15 minutes and then its
hanging.
I am not getting why this is happening.

Any help will be appreciated.

thanks in advance.

Nov 17 '05 #4

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

Similar topics

19
by: Thue Tuxen Sørensen | last post by:
Hi everybody ! I´m maintaining a large intranet (approx 10000 concurrent users) running on one IIS box and one DB box with sqlserver 2000. Currently there is 2,5 GB Ram, 1 1400 mhz cpu and 2...
6
by: MakeMeHappy | last post by:
Hi, I have some problems with understand how to call BeginInvoke properly so I need your help... I have a "worker" thread in my app where I download a website, and after some processing on html...
1
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from...
1
by: Chakkaradeep | last post by:
Hi all, i tried creating a UDP Asynchronous Server.....but am getting errors and am not able to figure out why!!!......... here is the code........... *****************************code...
5
by: Matthew Speed | last post by:
(About me: I know very little about writing server applications. I have done plenty of VB6 desktop app work but this is my first server program. I got it to work by modifying examples. I...
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...
25
by: Michael Kennedy | last post by:
Hi, I have been looking into the claim that the keyword lock is not safe when exceptions are possible. That lead me to try the following code, which I think has uncovered a serious error in the...
0
by: r1 | last post by:
I am relatively inexperienced in using delegates and asynchronous methods. I read several articles, and then I developed my own code with a mission to improve the performance. Wow! I cannot...
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
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
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: 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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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...

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.