A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.hangfire.io/en/latest/background-methods/calling-methods-in-background.html below:

Calling Methods in Background — Hangfire Documentation

  1. Documentation
  2. Background Methods
  3. Calling Methods in Background
  4. View page source
Calling Methods in Background¶

Fire-and-forget method invocation has never been simpler. As you already know from the Quick start guide, you only need to pass a lambda expression with the corresponding method and its arguments:

BackgroundJob.Enqueue(() => Console.WriteLine("Hello, world!"));

The Enqueue method does not call the target method immediately, it runs the following steps instead:

  1. Serialize a method information and all its arguments.

  2. Create a new background job based on the serialized information.

  3. Save background job to a persistent storage.

  4. Enqueue background job to its queue.

After these steps were performed, the BackgroundJob.Enqueue method immediately returns to a caller. Another Hangfire component, called Hangfire Server, checks the persistent storage for enqueued background jobs and performs them in a reliable way.

Enqueued jobs are handled by a dedicated pool of worker threads. The following process is invoked by each worker:

  1. Fetch next job and hide it from other workers.

  2. Perform the job and all its extension filters.

  3. Remove the job from the queue.

So, the job is removed only after processing succeeds. Even if a process was terminated during the performance, Hangfire will perform compensation logic to guarantee the processing of each job.

Each storage has its own implementation for each of these steps and compensation logic mechanisms:

Hangfire documentation is licensed under the

CC BY 4.0

.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4