2017-10-17 13 views
0

Webサイトの多くの例がC#であることは知っていますが、私はQuartzの.NET関数/メソッドを呼び出す必要があり、VB.Netを使用しています。Quartzから.NET関数/メソッドを呼び出す方法

多くの例は私がいることをどのように行うことができます

ファイル/アプリケーション/ exeファイルを開く方法について説明し、そうれている.NETの外部にある...しかし、私は、内部の何か(VBの関数/メソッド)を呼び出したい

お願いします?出来ますか?

以下を参照してください。

'define the job and tie it to our HelloJob class 
    IJobDetail job = JobBuilder.Create<HelloJob>() 
     .WithIdentity(myMethod(), "group1") 
     .Build(); 



Sub myMethod() 
    MsgBox("YES") 
End Sub 
+0

Quartからメソッドを呼び出すのではなく、Quartzスケジューラがメソッドを呼び出します。 IJobを実装するクラスを作成します。そのクラスでメソッドExecute()を追加し、クラスをQuart.Netに渡します。ジョブをスケジュールし、Quartzを実行すると、Execute()メソッドが呼び出されます。 – derloopkat

+0

ありがとうございました!!!私にVB.Netの例を教えてください。あなたはVB.Netコードを書くことができない場合でもC#をしてください。 – Jane

+0

私はVB.NetにC#のコードサンプルを翻訳して正常に動作しました。 Quartz.NetをNuGetパッケージからVB.Netコンソールプロジェクトに追加し、そのコードを使用するだけです。 – derloopkat

答えて

0

基本的に、あなたは、(それがIJob実装)クラスを作成する方法Executeを書いて、そこに自分のコードを置きます。 this tutorialをチェックしてください。スケジューラーを実行してジョブを渡す方法について説明しています。私は完全なサンプルコードをVB.Netに翻訳し、テストしました。

Imports System.Threading 
Imports Quartz 
Imports Quartz.Impl 
Imports Quartz.Job 

Module Module1 

    Sub Main() 
     Try 
      Common.Logging.LogManager.Adapter = New Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter() _ 
       With {.Level = Common.Logging.LogLevel.Info} 

      ' Grab the Scheduler instance from the Factory 
      Dim scheduler As IScheduler = StdSchedulerFactory.GetDefaultScheduler() 

      ' and start it off 
      scheduler.Start() 

      ' define the job and tie it to our HelloJob class 
      Dim job As IJobDetail = JobBuilder.Create(Of HelloJob)().WithIdentity("job1", "group1").Build() 

      ' Trigger the job to run now, and then repeat every 10 seconds 
      Dim trigger As ITrigger = TriggerBuilder.Create().WithIdentity("trigger1", "group1").StartNow().WithSimpleSchedule(Function(x) x.WithIntervalInSeconds(10).RepeatForever()).Build() 

      ' Tell quartz to schedule the job using our trigger 
      scheduler.ScheduleJob(job, trigger) 

      ' some sleep to show what's happening 
      Thread.Sleep(TimeSpan.FromSeconds(60)) 

      ' and last shut down the scheduler when you are ready to close your program 
      scheduler.Shutdown() 
     Catch se As SchedulerException 
      Console.WriteLine(se) 
     End Try 

     Console.WriteLine("Press any key to close the application") 
     Console.ReadKey() 
    End Sub 

    Public Class HelloJob 
     Implements IJob 
     Public Sub Execute(context As IJobExecutionContext) Implements IJob.Execute 
      Console.WriteLine("Greetings from HelloJob!") 
     End Sub 
    End Class 
End Module 

次のことはクロンを式を定義する方法を学んでいます。たとえば、毎週月曜日または毎月の最初の日にジョブを実行します。コンソールアプリケーションは、起動時に自動的に実行されるWindowsサービスとしてデプロイすることができ、期限が到来したらExecuteメソッドを呼び出すことができます。

関連する問題