0

我有一个页面在做某事,它可能需要 1,2 小时甚至更长时间......一段时间后我收到请求超时,我希望这个特定页面不会被请求超时 - 永远(或至少 24 小时)。

我该怎么做?

谢谢。

4

1 回答 1

0

您可以创建一个带有信号的线程,以了解它是否仍在运行。我建议使用互斥信号,因为它是唯一可以在许多池和线程中相同的信号。

线程代码可以是:

public class RunThreadProcess
{
    // Some parametres
    public int cProductID;

    // my thread
    private Thread t = null;

    // start it
    public Thread Start()
    {
        t = new Thread(new ThreadStart(this.work));
        t.IsBackground = true;
        t.SetApartmentState(ApartmentState.MTA);
        t.Start();

        return t;
    }

    // actually work
    private void work()
    {
        // while the mutex is locked, the thread is still working
        Mutex mut = new Mutex("WorkA");
        try
        {
            mut.WaitOne();

            // do thread work
            all parametres are available here

        }
        finally
        {
          mut.ReleaseMutex();
        }
    }
}

你称它为

 Mutex mut = new Mutex("WorkA");

 try
 {
 if(mut.WaitOne(1000))
 {
   // release it here to start it from the thread as signal
   mut.ReleaseMutex();
   // you start the thread
   var OneAction = new RunThreadProcess();

    OneAction.cProductID = 100;
    OneAction.Start();
  }
  else
  {
     // still running
  }
 }
 finally
 {
   mut.ReleaseMutex();
 }
于 2012-06-02T12:28:32.853 回答