fluentscheduler / FluentScheduler

Automated job scheduler with fluent interface for the .NET platform.
Other
2.68k stars 409 forks source link

Methods not running as a job is triggered #169

Closed thatsumoguy closed 5 years ago

thatsumoguy commented 7 years ago

I am trying to run a job that will do a button click method to change the state of a PauseTokenSource token. (PauseTokenSource is from here https://blogs.msdn.microsoft.com/pfxteam/2013/01/13/cooperatively-pausing-async-methods/).

The method works fine if I call it normally, but when trying to set it up to us FS and run after a trigger, it will fail to work.

`public

void Execute()
       {
           FolderMoveWindow FMW = new FolderMoveWindow();
           FMW.pauseBtn_Click();
           MessageBox.Show("Button Clicked");
      }`

This the Execute portion. The odd thing is, it will display the MessageBox with no issue. I even confirmed this is not working by having my pauseBtn_Click contain a listbox print out. Again if I call the method outside of FS it works, and I get the print out, but it fails in FS. There is no error output, or anything to indicate why it fails, but it's almost as if it skips over it.

I also tried to point Execute to a third method, which then called on the pauseBtn_Click and it also fails, but again works fine outside of FS.

tallesl commented 6 years ago

Hi there, sorry for taking so long to answer you.

I see that you're using the library from something like a Windows Forms/WPF application. Starting threads/tasks from a GUI application is a pain in the ***, maybe that's what's biting you. Fingers crossed to be something else, diving up on STA threads, dispatchers, synchronization contexts and alikes is no fun.

Do you have some code that reproduces what you mentioned that I can take a look at?

ajhalls commented 6 years ago

I stumbled on this thread that is perfect for what I needed as well. I am trying to develop a simple application that must have GUI components. It will be a service in the taskbar tray but must query the database every few minutes to check for changes, then post to a web server the results.

Is it inadvisable to try using FluentScheduler with a WPF application such as this: https://www.codeproject.com/Articles/1173686/A-Csharp-System-Tray-Application-using-WPF-Forms

So far I have just been trying to get it to append text to a TextBox, or pop up a MessageBox every 5 seconds as a proof of concept and can't get it to work.

thatsumoguy commented 6 years ago

I ended up setting a long running task and using a couple of timers that set each other off in place of FS in my app. It does the trick, but also sometimes likes to crash the app, so it's not perfect, but it can do for now.

But that does mean I don't have any code, and I lost the build that did use this with. I tried to keep copies of it while I was working so maybe I have a doc somewhere, if I do I will add it. But yeah I figured this was a UI thread problem, but I also figured it was worth a shot to try. Thanks for the reply.

ajhalls commented 6 years ago

Thanks for letting me know. I am trying to avoid writing my own timers as it seems like leveraging a full blown library like this would be more reliable. I am surprised I haven't found more support for WPF scheduling.