|
Hi,
I'm running into a very strange behavior of HttpWebRequest.BeginGetResponse().
Instead of returning immediately, and executing the request in a new Thread from the ThreadPool, the method blocks, and the request is executed in the same thread. Actually, it behaves like HttpWebRequest.GetResponse().
Basically I do a very simple task, in which I call a big number of web requests and run them asynchronously:
private void scheduleMyWebRequests()
{
for (int i = 0; i < someNumber; i++)
{
…
IAsyncResult result = httpWebReq.BeginGetRespons(processMyData, state);
ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, timeoutCallback, state, timeout, true);
}
}
private void processMyData (IAsyncResult result)
{
...
...
if(noMoreRequestsToProcess)
callAnotherMethodToContinue()
}
This code works perfectly when the web requests use HttpMethod.GET
All the requests run asyncronously.
However, when I started using requests which are HttpMethod.POST something strange happens:
After the first BegineGetResponce() the control doen't return immediately.
Instead, the same thread starts runing the processMydata() method. Only when this method finishes, the control returns to the calling method.
All my web requests are performed syncronously rather then asyncronously (I've dumped the Thread's Id and all the calles use the same Thread Id).
When I use HttpMethod.Get I can see that indeed, each request uses a different Thread Id, as expected.
Does anyone have a clue why is this happening?
P.S. the cause is not an unhandled exception. I've already checked…
Tnx
Roy
|
|
|
|
|
Have you read the relevant documentation? One page of it says:
"Your application cannot mix synchronous and asynchronous methods for a particular request. "
maybe that rings a bell?
|
|
|
|
|
Yes, I've read the document and i'm well aware of this fact.
I'm not performing any syncronous requests at all. Only asyncronous.
Tnxanyway...
|
|
|
|
|
Hi
This my connectionstring to my sql database that the database file position is : C:\Users\hossein\Desktop\MyProject\MyProject\bin\Debug\Data
string constr =
"Data Source=.;DataBase="+System.Windows.Forms.Application.StartupPath+"\\Data\\mydatabase.mdf;"
+"Integrated Security=true";
sqlconnection con=new sqlconnection();
con.open();
I have error when compiler want to compile "con.open()" and error is "compiler can't open mydatabase"
what should i do?
|
|
|
|
|
While adopting exception handling techniques, is the compiler able to give correct answers or we just handle those conditions by printing an error message using longjmp() etc?
Like in the following program the square of 1000000 would overflow? So can the compiler print its original result? And also in other cases such as " ArrayTypeMismatchException ", what technique is adopted to handle it?
int square(int i)
{
return i * i;
}
void f()
{
checked
{
int i = square(1000000);
}
}
|
|
|
|
|
Razanust wrote: checked
{
int i = square(1000000);
}
Will throw an Exception; you should catch it and display a message or something.
|
|
|
|
|
My need is to schedulle to run a C# application once a day for some days of the week
And I provide an UI to set those days
So I was trying to find out if the best way is to make a service to do that or to programaticaly try to make a new Windows task to run the app as an exe
Thanks for your help / suggestion
Olivier
|
|
|
|
|
CP link [^].
There's nothing left in my right brain and nothing right in my left brain. |
|
|
|
|
|
you could tell Windows to run it once a day, then in your code skip the days that you don't want any action taken. day selection information could be kept in a settings file, a separate file, the registry, whatever, which some app could display and modify through a GUI.
|
|
|
|
|
Thank you
Very nice Idea !!
Of course I already have my own setting file !
Unfortunately the user wants also to set the time for the given days
|
|
|
|
|
Thank you Luc
Yes I know that link but I do not feel confident with that solution
1- I can't compile it because the post compile event wants to run mt.exe and I don't know why ?
2- As I can see it uses an uggly old fashion dos interface
3- At the first sight I thougt that the goal for that app was to create or edit Windows .job files and let Windows scheduller do the job. If so I do not understand why it needs 7 files of about 100k of source code to do that ?
I'm afraid that this is just another scheduller !
But till now it's purpose is not clear to me ?
|
|
|
|
|
I think that wasn't meant for me; maybe it is your reply to Abhinav S?
|
|
|
|
|
I think that wasn't meant for me; maybe it is your reply to Abhinav S?
Indeed ! sorry for the mistake
|
|
|
|
|
Luc Pattyn wrote: then in your code skip the days that you don't want
Ew. So how do you test it on those days? Or what if you change your mind?
|
|
|
|
|
Hello
The idea of Luc was very simple (as most of good idea)
Let say that I have a settings file giving the needed days (this is the case)
When the application start it will check that files and decide to run the process or close
So if the Windows scheduller start the application every days the task will only start for the needed days
An independent UI (Web Page) can change the setting file at any time
The Idea was great but unfortunately not for this case because the User can also choose the starting time
|
|
|
|
|
I disagree; I don't think the application should be responsible for its own scheduling.
And if you later have to develop other similar applications, you would likely wind up with a bunch of duplicate code.
Having the scheduling handled outside the application allows it to be shared among any number of applications.
And Windows already has a built-in Scheduler that will do what you want; why not use it?
|
|
|
|
|
Use a Windows Scheduled Task to schedule for only those days and times you want it to run.
|
|
|
|
|
Ok
Have a look on the environnement
The application should run on a server
ONE user uses an interface (web page) on a remote machine to set up the days an time he wants to get some rapport
The question is what would be the best way to automaticaly set up the Windows scheduller on the server when the user changes his mind ?
|
|
|
|
|
Well that's a whole other situation than what you described in the original post.
And in that case, I agree with a Windows Service that executes the task when specified. I have written such a scheduler. Tasks were scheduled in a database via whatever client (I used WinForms). I will further state that I stopped using my task scheduler when I made my report scheduler.
baranils wrote: to get some rapport
I'll assume you mean report. Are the reports generated by Crystal or another report system? If so, I suggest a Service that executes the report more directly, without some other executable in between.
|
|
|
|
|
Hello PIEBALDconsult
Well that's a whole other situation than what you described in the original post.
Not really :
My need is to schedulle to run a C# application once a day for some days of the week
And I provide an UI to set those days
As I said my C# application do the job (getting date, create report)
My application can also read the xml setings file created by the UI
I can of course run my application as a service but I see some advantage to keep it as an exe file and try to les Windows schedulle it
1- As long as it only needs to run maximum once a day it is not efficient to let a servis running all the time
2- With an exe we keep the ability to manualy launch som "extra run" if needed
|
|
|
|
|
Don't think so small. If this project is a success they'll ask you to write other such reports that may have to run more than once a day or on demand.
It'll be easier in the long run if you provide such flexibility from the start.
|
|
|
|
|
Yes of course,
I agree with you, but practicaly I'll still be happy to understand how to setup the windows scheduller programatically
Maybe by simply execute taskschd.exe using System.Diagnostics.Process.Start?
|
|
|
|
|
baranils wrote: execute taskschd.exe
That's how I've done it in the past. But there oughta be a better way.
|
|
|
|
|
PIEBALDconsult wrote: That's how I've done it in the past. But there oughta be a better way.
Do you know some ?
|
|
|
|
|
No, and I just found this[^].
|
|
|
|