2011-06-21 3 views
0

私は、ASP.NET MVC 2で書かれたアプリケーションを使用して、ユーザーのスケジュールされたイベントの日時をMSSQLデータベースに格納しています。私は、手動の介入なしにストアドイベントが発生する72時間前に、ユーザーに電子メールアラートを送信するアプリケーションが必要です。電子メール警告を起動して送信する並列プロセススケジュールされたイベントの72時間前

この並列プロセスを実装する最良の方法は何ですか(私はすでに電子メールコードを持っています)。

+0

このプロセスについては何が平行していますか? – bzlm

+0

電子メールアラートは、他のアプリケーション機能と並行して送信されています。 – kmullings

+0

これはその言葉の非正統的な使用です。 :) – bzlm

答えて

0

データベースにイベントが格納されていると仮定して、asp.netアプリケーションとは独立して動作するWindowsサービスを作成し、データベースを定期的にポーリングして作業を探していました。

0

サーバーを管理している場合は、おそらくWindowsサービス(The Evil Greebo saidなど)を使用します。

しかし、そうでないと仮定すると、おそらく以下のようなクラスを作成します。このクラスは、/ inheritから使用できます。 global.asaxの "Application_start"イベント中にこのクラスをインスタンス化し、そのコピーをキャッシュに保存します。あなたのロジックを "ExecuteProcess"メソッドに入れてください。あなたのロジックは、おそらく(擬似コード)のようなものになります。

while(true) 
    check for events that need to have notifications sent 

    send any needed notifications 

    wait x seconds and repeate 

loop 

を使用すると、通知が送信されたかどうかを追跡するためにあなたのMSSQLデータベーステーブル内のフィールドを持っていることを確認してください。

基本ベースクラス:

Imports System.Threading 

Public MustInherit Class LongRunningProcess 
    Public ReadOnly Property Running() As Boolean 
     Get 
      Return _Running 
     End Get 
    End Property 

    Public ReadOnly Property Success() As Boolean 
     Get 
      Return _Success 
     End Get 
    End Property 

    Public ReadOnly Property Exception() As Exception 
     Get 
      Return _Exception 
     End Get 
    End Property 

    Public ReadOnly Property StartTime() As DateTime 
     Get 
      Return _StartTime 
     End Get 
    End Property 

    Public ReadOnly Property EndTime() As DateTime 
     Get 
      Return _EndTime 
     End Get 
    End Property 

    Public ReadOnly Property Args() As Object 
     Get 
      Return _Args 
     End Get 
    End Property 


    Protected _Running As Boolean = False 
    Protected _Success As Boolean = False 
    Protected _Exception As Exception = Nothing 
    Protected _StartTime As DateTime = DateTime.MinValue 
    Protected _EndTime As DateTime = DateTime.MinValue 
    Protected _Args() As Object = Nothing 
    Protected WithEvents _Thread As Thread 

    Private _locker As New Object() 

    Public Sub Execute(ByVal Arguments As Object) 
     SyncLock (_locker) 
      'if the process is not running, then...' 
      If Not _Running Then 
       'Set running to true' 
       _Running = True 
       'Set start time to now' 
       _StartTime = DateTime.Now 
       'set arguments' 
       _Args = Arguments 
       'Prepare to process in a new thread' 
       _Thread = New Thread(New ThreadStart(AddressOf ExecuteProcess)) 

       'Start the thread' 
       _Thread.Start() 
      End If 
     End SyncLock 
    End Sub 

    Protected MustOverride Sub ExecuteProcess() 
End Class 

Argsのプロパティは、あなたが必要な場合があります任意の引数/変数に「ExecuteProcess」内からアクセスできます。

+0

私はサーバーを制御できないので、C#であなたのソリューションを書き直して試してみましょう - ありがとう! – kmullings

関連する問題