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

Multithreading in ASP.NET app???

JV
My ASP.NET application needs to accept data from a post and return quickly.
I've added a worker thread to wake up and save data asynchronously after the
data is received. But, it appears to me that IIS kills the process and
thus the worker thread right after my main ASP.NET thread returns (anyone
know for certain?).

Do you know of a design pattern to accomplish this?
Mar 13 '06 #1
29 1089
JV,

You have to figure out for what reason ASP.NET is killing the process.
ASP.NET does have application recycling if the app goes down, and sometimes,
if memory consumption is too high, it will recycle the process.

What I would recommend is writing a service that will perform this
operation for you, then using a technology like MSMQ (through
System.Messaging) to send a message to the service, which will then handle
the updating of the data.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?

Mar 13 '06 #2
Hi,

Check this out...

/Oscar

//Buisness layer...gets called from an ASP.NET web page...
public bool InitAsyncOperation(string someData)
{
try
{
//Access layer
Access access = Access.GetInstance(CurrentUser);

if(access.IsRunning)
{
return false;
}
else
{
//First we do some sync operation...
Wrapper wrapper = access.Validate(someData);

//Then we kick of the async...
MyDelegate d = new MyDelegate(<Another method...that performs the async
operation...>);
AsyncHelper.Execute(d, wrapper);
}
}
catch(Exception ex)
{
if(ExceptionPolicy.HandleException(ex, CONTROLLER_EXCEPTION_POLICY))
throw;
}

return true;
}


///Class AsyncHelper
using System;
using System.Reflection;
using System.Threading;

namespace <SomeCompany>.<SomeApp>.Util
{
/// <summary>
/// Starting with the 1.1 release of the .NET Framework, the SDK docs
/// now carry a caution that mandates calling EndInvoke on delegates
/// you've called BeginInvoke on in order to avoid potential leaks.
/// This means you cannot simply "fire-and-forget" a call to BeginInvoke
/// when spawning a new worker thread from the thread pool without the
risk
/// of creating a memory leak.
///
/// The usage model is that instead of calling BeginInvoke against a
delegate,
/// you would instead call AsyncHelper.Execute, passing that delegate and
it's parameters as input.
/// See: http://staff.develop.com/woodring for further information.
/// </summary>
/// <example>
/// delegate void CalcAndDisplaySumDelegate( int a, int b );
/// CalcAndDisplaySumDelegate d = new
CalcAndDisplaySumDelegate(someCalc.Add);
/// AsyncHelper.Execute(d, 2, 3);
/// </example>
public class AsyncHelper
{
private static WaitCallback callback = new
WaitCallback(DynamicInvokeShim);

/// <summary>
/// Takes a delegate and a list of arguments. Performs asynchronous
invocation of the
/// target(the Class.Method the delegates points to..).
/// </summary>
/// <param name="d"></param>
/// <param name="args"></param>
/// <Author>Oscar Thornell</Author>
public static void Execute(Delegate d, params object[] args)
{
ThreadPool.QueueUserWorkItem(callback, new TargetInfo(d, args));
}

private static void DynamicInvokeShim(object obj)
{
TargetInfo targetInfo = (TargetInfo)obj;
targetInfo.Target.DynamicInvoke(targetInfo.Args);
}

class TargetInfo
{
internal readonly Delegate Target;
internal readonly object[] Args;

internal TargetInfo(Delegate d, object[] args)
{
Target = d;
Args = args;
}
}
}
}

"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?

Mar 13 '06 #3
As you observed, you are not gaining much with multithreading in Asp.Net.

You can make a Windows service that will pick up requests made by the
Asp.Net application. The requests can be passed on in a number of ways. Two
most common ones are via a database and via files.

Eliyahu

"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?

Mar 13 '06 #4
I wouldn't recommend using a database or files for notifications to the
service. That would require you to poll for the result, which on a general
level, is not too efficient.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OW****************@tk2msftngp13.phx.gbl...
As you observed, you are not gaining much with multithreading in Asp.Net.

You can make a Windows service that will pick up requests made by the
Asp.Net application. The requests can be passed on in a number of ways.
Two most common ones are via a database and via files.

Eliyahu

"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?


Mar 13 '06 #5
System.IO.FileSystemWatcher is a nice class that takes care of notification
in case of files.

Eliyahu

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ek**************@TK2MSFTNGP11.phx.gbl...
I wouldn't recommend using a database or files for notifications to the
service. That would require you to poll for the result, which on a
general level, is not too efficient.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OW****************@tk2msftngp13.phx.gbl...
As you observed, you are not gaining much with multithreading in Asp.Net.

You can make a Windows service that will pick up requests made by the
Asp.Net application. The requests can be passed on in a number of ways.
Two most common ones are via a database and via files.

Eliyahu

"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?



Mar 13 '06 #6
Eliyahu Goldin wrote:
System.IO.FileSystemWatcher is a nice class that takes care of notification
in case of files.


Not reliably, in my experience. I don't know *exactly* what goes wrong,
but often FileSystemWatcher can end up missing events, or waiting a
while and then delivering batches etc. I'm not the only one to have
noticed this. I still use FSW, but only in conjunction with something
which manually polls in case something goes wrong. It's all a bit of a
hack :(

Jon

Mar 13 '06 #7
JV
I've only skimmed over your code thus far, but it appears you are spawning a
thread from the threadpool for each ASP.NET request? If I'm correct about
that, that would become a scalability issue.
My goal is to have a single worker thread that manages the dataset and
multiple requests putting/getting data. Wish I could have just used MSSQL
for this.
"Oscar Thornell" <no****@internet.com> wrote in message
news:ec**************@TK2MSFTNGP09.phx.gbl...
Hi,

Check this out...

/Oscar

//Buisness layer...gets called from an ASP.NET web page...
public bool InitAsyncOperation(string someData)
{
try
{
//Access layer
Access access = Access.GetInstance(CurrentUser);

if(access.IsRunning)
{
return false;
}
else
{
//First we do some sync operation...
Wrapper wrapper = access.Validate(someData);

//Then we kick of the async...
MyDelegate d = new MyDelegate(<Another method...that performs the
async operation...>);
AsyncHelper.Execute(d, wrapper);
}
}
catch(Exception ex)
{
if(ExceptionPolicy.HandleException(ex, CONTROLLER_EXCEPTION_POLICY))
throw;
}

return true;
}


///Class AsyncHelper
using System;
using System.Reflection;
using System.Threading;

namespace <SomeCompany>.<SomeApp>.Util
{
/// <summary>
/// Starting with the 1.1 release of the .NET Framework, the SDK docs
/// now carry a caution that mandates calling EndInvoke on delegates
/// you've called BeginInvoke on in order to avoid potential leaks.
/// This means you cannot simply "fire-and-forget" a call to
BeginInvoke
/// when spawning a new worker thread from the thread pool without the
risk
/// of creating a memory leak.
///
/// The usage model is that instead of calling BeginInvoke against a
delegate,
/// you would instead call AsyncHelper.Execute, passing that delegate and
it's parameters as input.
/// See: http://staff.develop.com/woodring for further information.
/// </summary>
/// <example>
/// delegate void CalcAndDisplaySumDelegate( int a, int b );
/// CalcAndDisplaySumDelegate d = new
CalcAndDisplaySumDelegate(someCalc.Add);
/// AsyncHelper.Execute(d, 2, 3);
/// </example>
public class AsyncHelper
{
private static WaitCallback callback = new
WaitCallback(DynamicInvokeShim);

/// <summary>
/// Takes a delegate and a list of arguments. Performs asynchronous
invocation of the
/// target(the Class.Method the delegates points to..).
/// </summary>
/// <param name="d"></param>
/// <param name="args"></param>
/// <Author>Oscar Thornell</Author>
public static void Execute(Delegate d, params object[] args)
{
ThreadPool.QueueUserWorkItem(callback, new TargetInfo(d, args));
}

private static void DynamicInvokeShim(object obj)
{
TargetInfo targetInfo = (TargetInfo)obj;
targetInfo.Target.DynamicInvoke(targetInfo.Args);
}

class TargetInfo
{
internal readonly Delegate Target;
internal readonly object[] Args;

internal TargetInfo(Delegate d, object[] args)
{
Target = d;
Args = args;
}
}
}
}

"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?


Mar 13 '06 #8
Hi,
"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data


TO wake up ?
How r u storing the thread reference? in Application ?
How r u running it?
Show some code for more details.

What if you create the thread at each request? This allow you to create one
thread per request and not having to worry about concurrency, the drawback
is that you may create lots of threads depending of how busy is your web
site.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Mar 13 '06 #9
I create a worker thread from within an ASPX page as follows (code is
actually in a server control used in the page, so it is defined in its
own named assembly):

System.Threading.ThreadStart ts = new
System.Threading.ThreadStart(ProcessCleanupFiles);
System.Threading.Thread thread = new System.Threading.Thread(ts);
thread.Start();

The page returns in a timely fashion and the thread survives to do
cleanup. For testing I tried putting a 30 second sleep into
ProcessCleanupFiles to test that a) it did not slow my page return b)
it does execute after the delay. I have not explicitly tested for
memory leaks but based on my understanding, "thread" should get cleaned
up sometime after both the invoking method and ProcessCleanupFiles
complete.

Mar 13 '06 #10
JV
Thanks for the reply!

Actually I was storing the reference to the object in Session, but I could
just as easily move it to Application. That would actually make more sense.

I am trying to avoid creating a thread per request. That sort of defeats
the purpose of returning quickly for scalability.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:uc**************@TK2MSFTNGP14.phx.gbl...
Hi,
"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data


TO wake up ?
How r u storing the thread reference? in Application ?
How r u running it?
Show some code for more details.

What if you create the thread at each request? This allow you to create
one thread per request and not having to worry about concurrency, the
drawback is that you may create lots of threads depending of how busy is
your web site.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Mar 13 '06 #11
JV,

What does your mainthread do in the meantime.

With the information you give now, do I not see any sense for
multithreading.

Moreover the only thing you achieve is that your processing time will be
take more time.

Just my thought,

Cor
"JV" <oy********@spammenot.com> schreef in bericht
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?

Mar 13 '06 #12
Hi,

How much time the DB operation takes?

Do not store it in application, if you do so ALL the sessions will try to
use it.

If the DB operation takes a long time using MSQS would be a good suggestion
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"JV" <oy********@spammenot.com> wrote in message
news:ut**************@TK2MSFTNGP14.phx.gbl...
Thanks for the reply!

Actually I was storing the reference to the object in Session, but I could
just as easily move it to Application. That would actually make more
sense.

I am trying to avoid creating a thread per request. That sort of defeats
the purpose of returning quickly for scalability.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote in message news:uc**************@TK2MSFTNGP14.phx.gbl...
Hi,
"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data


TO wake up ?
How r u storing the thread reference? in Application ?
How r u running it?
Show some code for more details.

What if you create the thread at each request? This allow you to create
one thread per request and not having to worry about concurrency, the
drawback is that you may create lots of threads depending of how busy is
your web site.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Mar 13 '06 #13
Hi,

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Eliyahu Goldin wrote:
System.IO.FileSystemWatcher is a nice class that takes care of
notification
in case of files.


Not reliably, in my experience. I don't know *exactly* what goes wrong,
but often FileSystemWatcher can end up missing events, or waiting a
while and then delivering batches etc. I'm not the only one to have
noticed this. I still use FSW, but only in conjunction with something
which manually polls in case something goes wrong. It's all a bit of a
hack :(


Totally agree with you in this, not only you may lose events ( not my case
so far) but you may get duplicated events for a single user action. I use a
lock while processing and deleting(or moving) files as a workaround.

Anyway files are not the best option for the OP's problem

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Mar 13 '06 #14
JV,
I see no reason why you couldn't have a class in Application State that
would hold a DataSet whose table to which you would add your post data.
Whenever a new row is added (or when "x" number of rows had been added) the
class would perform an DataAdapter Update to your Sql server and clear out
the datatable to wait for more posts.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"JV" wrote:
My ASP.NET application needs to accept data from a post and return quickly.
I've added a worker thread to wake up and save data asynchronously after the
data is received. But, it appears to me that IIS kills the process and
thus the worker thread right after my main ASP.NET thread returns (anyone
know for certain?).

Do you know of a design pattern to accomplish this?

Mar 13 '06 #15
JV
The goal is to allow the main thread to append some data or request some
data from a dataset. But persistence would be managed on another thread so
as not to slow up the ASP.NET application unless necessary.

Idea was to use a ManualResetEvent to let the worker thread know there was
some work to do and a Mutex to serialize access to the data. Thus, if many
requests were coming in close together, the worker thread might have to wait
awhile to do persistence, but the ASP.NET application could carry on with
the in-memory data.

Why would you say that this increases processing time? Maybe in total, but
performance for the ASP.NET application should be increased, which is the
key.
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:uo**************@tk2msftngp13.phx.gbl...
JV,

What does your mainthread do in the meantime.

With the information you give now, do I not see any sense for
multithreading.

Moreover the only thing you achieve is that your processing time will be
take more time.

Just my thought,

Cor
"JV" <oy********@spammenot.com> schreef in bericht
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?


Mar 13 '06 #16

The problem is your code is finishing before the worker thread
completes. You need a method to evaluate that the worker thread has
completed before allow the ASP.NET application to end.

I use this pattern

//put my process on a thread
results.Add(this.as400maketable(s,tableString));

//the threaded method
private IAsyncResult as400maketable(string line, string tablename)
{
AsyncCallback delCB = new AsyncCallback(this.AsyncCB);
IAsyncResult ar = null;
//does a DB2 database insert
ar = as400.BegininsertData(line, tablename, delCB, null);
return ar;
}

//callback method
void AsyncCB(IAsyncResult ar)
{
as400.EndinsertPolarData(ar);
}

//Then back in my main thread I check to see all my threads are done:
foreach(IAsyncResult ar in results)
ar.AsyncWaitHandle.WaitOne();
JV wrote:
My ASP.NET application needs to accept data from a post and return quickly.
I've added a worker thread to wake up and save data asynchronously after the
data is received. But, it appears to me that IIS kills the process and
thus the worker thread right after my main ASP.NET thread returns (anyone
know for certain?).

Do you know of a design pattern to accomplish this?

Mar 13 '06 #17
John Bailo <ja*****@texeme.com> wrote:
The problem is your code is finishing before the worker thread
completes. You need a method to evaluate that the worker thread has
completed before allow the ASP.NET application to end.


No, the whole point is (as I understand it) to make the web page return
quickly, queueing the data for insert later as it will take some time.
Unfortunately the way that IIS recycles AppDomains etc can make this
somewhat flaky. Instead of starting separate threads and assuming
they'll continue, the OP will need to queue the data in a more robust
way (eg to the file system or MSMQ) before returning, possibly
processing it in a different process altogether.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 14 '06 #18
JV,

See this

Page load
Start workerthread
Do some things in the mainthread
Let main thread sleep in a processing loop to see if the workerthread is
ready and if ready go on
(otherwise the page is sent back and this page goes out of scope)
Sent page back

What is your advantage in this, that really should in my opinion really be
hug if it is in an ASPNET application more than the processing needed for
the threads and the checking of those are ready(it is not your code however
what is needed)?

And the processor is of course not only used by this client.

I hope this helps,

Cor

"JV" <oy********@spammenot.com> schreef in bericht
news:eC**************@tk2msftngp13.phx.gbl...
The goal is to allow the main thread to append some data or request some
data from a dataset. But persistence would be managed on another thread
so as not to slow up the ASP.NET application unless necessary.

Idea was to use a ManualResetEvent to let the worker thread know there was
some work to do and a Mutex to serialize access to the data. Thus, if
many requests were coming in close together, the worker thread might have
to wait awhile to do persistence, but the ASP.NET application could carry
on with the in-memory data.

Why would you say that this increases processing time? Maybe in total,
but performance for the ASP.NET application should be increased, which is
the key.
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:uo**************@tk2msftngp13.phx.gbl...
JV,

What does your mainthread do in the meantime.

With the information you give now, do I not see any sense for
multithreading.

Moreover the only thing you achieve is that your processing time will be
take more time.

Just my thought,

Cor
"JV" <oy********@spammenot.com> schreef in bericht
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?



Mar 14 '06 #19
Thats correct! It works in my solution, since the use case is to start a
batch like process that doesn´t happen to often...and let the user proceed
to other tasks..
I think that you should try using the threadpool and test the performance...

/Oscar

"JV" <oy********@spammenot.com> wrote in message
news:OK**************@TK2MSFTNGP09.phx.gbl...
I've only skimmed over your code thus far, but it appears you are spawning
a thread from the threadpool for each ASP.NET request? If I'm correct
about that, that would become a scalability issue.
My goal is to have a single worker thread that manages the dataset and
multiple requests putting/getting data. Wish I could have just used
MSSQL for this.
"Oscar Thornell" <no****@internet.com> wrote in message
news:ec**************@TK2MSFTNGP09.phx.gbl...
Hi,

Check this out...

/Oscar

//Buisness layer...gets called from an ASP.NET web page...
public bool InitAsyncOperation(string someData)
{
try
{
//Access layer
Access access = Access.GetInstance(CurrentUser);

if(access.IsRunning)
{
return false;
}
else
{
//First we do some sync operation...
Wrapper wrapper = access.Validate(someData);

//Then we kick of the async...
MyDelegate d = new MyDelegate(<Another method...that performs the
async operation...>);
AsyncHelper.Execute(d, wrapper);
}
}
catch(Exception ex)
{
if(ExceptionPolicy.HandleException(ex, CONTROLLER_EXCEPTION_POLICY))
throw;
}

return true;
}


///Class AsyncHelper
using System;
using System.Reflection;
using System.Threading;

namespace <SomeCompany>.<SomeApp>.Util
{
/// <summary>
/// Starting with the 1.1 release of the .NET Framework, the SDK docs
/// now carry a caution that mandates calling EndInvoke on delegates
/// you've called BeginInvoke on in order to avoid potential leaks.
/// This means you cannot simply "fire-and-forget" a call to
BeginInvoke
/// when spawning a new worker thread from the thread pool without the
risk
/// of creating a memory leak.
///
/// The usage model is that instead of calling BeginInvoke against a
delegate,
/// you would instead call AsyncHelper.Execute, passing that delegate and
it's parameters as input.
/// See: http://staff.develop.com/woodring for further information.
/// </summary>
/// <example>
/// delegate void CalcAndDisplaySumDelegate( int a, int b );
/// CalcAndDisplaySumDelegate d = new
CalcAndDisplaySumDelegate(someCalc.Add);
/// AsyncHelper.Execute(d, 2, 3);
/// </example>
public class AsyncHelper
{
private static WaitCallback callback = new
WaitCallback(DynamicInvokeShim);

/// <summary>
/// Takes a delegate and a list of arguments. Performs asynchronous
invocation of the
/// target(the Class.Method the delegates points to..).
/// </summary>
/// <param name="d"></param>
/// <param name="args"></param>
/// <Author>Oscar Thornell</Author>
public static void Execute(Delegate d, params object[] args)
{
ThreadPool.QueueUserWorkItem(callback, new TargetInfo(d, args));
}

private static void DynamicInvokeShim(object obj)
{
TargetInfo targetInfo = (TargetInfo)obj;
targetInfo.Target.DynamicInvoke(targetInfo.Args);
}

class TargetInfo
{
internal readonly Delegate Target;
internal readonly object[] Args;

internal TargetInfo(Delegate d, object[] args)
{
Target = d;
Args = args;
}
}
}
}

"JV" <oy********@spammenot.com> wrote in message
news:Oi*************@TK2MSFTNGP10.phx.gbl...
My ASP.NET application needs to accept data from a post and return
quickly. I've added a worker thread to wake up and save data
asynchronously after the data is received. But, it appears to me that
IIS kills the process and thus the worker thread right after my main
ASP.NET thread returns (anyone know for certain?).

Do you know of a design pattern to accomplish this?



Mar 14 '06 #20
I typed "realy" and thought "workerprocess"
What is your advantage in this, that really should in my opinion really be
hug if it is in an ASPNET application more than the processing needed for
the threads and the checking of those are ready(it is not your code
however what is needed)?

What is your advantage in this, that workerprocess should in my opinion
really be hug if it is in an ASPNET application and use more time than the
.................................................. ..............

By the way if you need data only for showing, than you can set your data in
a shared/static class.

That data stays in your server as long as there are sessions active for your
application (including session time). So you have to make a procedure in a
way that it refresh if the application stops. If it is a 24 hours used
application (which never will stop), than you have also to make something to
force cleaning up.

If you need a sample for this, reply than I copy something (although that is
than simple VB.Net).

I hope this helps,

Cor


Mar 14 '06 #21
Jon Skeet [C# MVP] wrote:

Instead of starting separate threads and assuming
they'll continue, the OP will need to queue the data in a more robust
way (eg to the file system or MSMQ) before returning, possibly
processing it in a different process altogether.


Why bother, when he can can easily, as I have, create his own thread pool?

Mar 14 '06 #22
John Bailo <ja*****@texeme.com> wrote:
Instead of starting separate threads and assuming
they'll continue, the OP will need to queue the data in a more robust
way (eg to the file system or MSMQ) before returning, possibly
processing it in a different process altogether.


Why bother, when he can can easily, as I have, create his own thread pool?


Because having your own thread pool doesn't help if IIS decides to kill
your process.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 14 '06 #23
Jon,

I am using FSW extensively in a multi-threaded Windows service project. It
has been deployed to numerous client sites and there are no known
FSW-related problems. I think the problems you and the other poster are
observing could be caused by your handling FSW events rather than its faulty
behavior.

I do have a backup polling thread just in case if FSW misses something.

Eliyahu

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Eliyahu Goldin wrote:
System.IO.FileSystemWatcher is a nice class that takes care of
notification
in case of files.


Not reliably, in my experience. I don't know *exactly* what goes wrong,
but often FileSystemWatcher can end up missing events, or waiting a
while and then delivering batches etc. I'm not the only one to have
noticed this. I still use FSW, but only in conjunction with something
which manually polls in case something goes wrong. It's all a bit of a
hack :(

Jon

Mar 15 '06 #24
Eliyahu Goldin wrote:
I am using FSW extensively in a multi-threaded Windows service project. It
has been deployed to numerous client sites and there are no known
FSW-related problems. I think the problems you and the other poster are
observing could be caused by your handling FSW events rather than its faulty
behavior.
FSW has been observed to be problematic by many people. In my case, the
event handling is very simple indeed. There may well be some scenarios
where it works perfectly and some where it doesn't, depending on which
events are being listened for and what is actually occurring.

Given the number of people who've had problems (and these aren't
novices, btw) I think it's reasonable to suppose that there are genuine
problems in FSW.
I do have a backup polling thread just in case if FSW misses something.


Does that mean you might not have seen any FSW problems even if they're
occurring?

Jon

Mar 15 '06 #25

Same here.

I use FSW in windows services for monitoring ftp transfers and its
always worked flawlessly.

Eliyahu Goldin wrote:
Jon,

I am using FSW extensively in a multi-threaded Windows service project. It
has been deployed to numerous client sites and there are no known
FSW-related problems. I think the problems you and the other poster are
observing could be caused by your handling FSW events rather than its faulty
behavior.

I do have a backup polling thread just in case if FSW misses something.

Eliyahu

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Eliyahu Goldin wrote:
System.IO.FileSystemWatcher is a nice class that takes care of
notification
in case of files.

Not reliably, in my experience. I don't know *exactly* what goes wrong,
but often FileSystemWatcher can end up missing events, or waiting a
while and then delivering batches etc. I'm not the only one to have
noticed this. I still use FSW, but only in conjunction with something
which manually polls in case something goes wrong. It's all a bit of a
hack :(

Jon


Mar 22 '06 #26
check out MSMQ with Triggers. i use them in a number of cases where i
want to post a 'job' via the web and have the server process the
details async or at some later time.

google: MSMQ Trigger example

and you should be able to find a few code examples to work with.

Mar 22 '06 #27
John Bailo <ja*****@texeme.com> wrote:
Same here.

I use FSW in windows services for monitoring ftp transfers and its
always worked flawlessly.


Several people have reported updating UI controls from worker threads
without problems - until they hit a problem. Something working for you
(so far) doesn't prove there isn't an issue.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 22 '06 #28
Jon Skeet [C# MVP] wrote:
Several people have reported updating UI controls from worker threads
without problems - until they hit a problem. Something working for you
(so far) doesn't prove there isn't an issue.


Yes, but I think here the burden of proof would be on the skills of the
person writing the threaded application, before I go an accuse a .NET
class (which is used by millions beyond this ng) as being flawed.
--
http://www.you-saw-it-here-first.com
fueled by Texeme Textcasting
Mar 22 '06 #29
John Bailo wrote:
Several people have reported updating UI controls from worker threads
without problems - until they hit a problem. Something working for you
(so far) doesn't prove there isn't an issue.


Yes, but I think here the burden of proof would be on the skills of the
person writing the threaded application, before I go an accuse a .NET
class (which is used by millions beyond this ng) as being flawed.


And if I could reproduce the problem reliably, I'd do just that.
However, as tends to be the case with this kind of issue, reproducing
it in isolation is extremely tricky.

I understand your reluctance, but I'm no threading slouch myself and
the other MVPs who I've seen complaining of problems with FSW are
likewise skilled developers.

In the case I'm thinking of (which I can't unfortunately post the code
for) the code is extremely simple, and I've been through it very
carefully several times. Maybe I'll have a go at reproducing it at
home, and see what I can do - it would certainly be useful to have it
fixed.

Jon

Mar 22 '06 #30

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

Similar topics

1
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...
47
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
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
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...
9
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...
2
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...
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...
5
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...
2
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...
7
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...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.