Last active
November 30, 2017 18:56
-
-
Save tluyben/f8bc48ad9463810995fb49f8aec54340 to your computer and use it in GitHub Desktop.
Hangfire actions without all the serialization issues (won't survive server restart or multiple servers, but easier to make that work as well)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Random r = new Random(); | |
static ConcurrentDictionary<int, Action> actions = new ConcurrentDictionary<int, Action>(); | |
public static void ExecuteAction(int i) | |
{ | |
Action a; | |
actions.Remove(i, out a); | |
a(); | |
} | |
public void Background(Action a) | |
{ | |
var i = r.Next(); | |
actions[i] = a; | |
Hangfire.BackgroundJob.Enqueue(()=>MyCron.ExecuteAction(i)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment