1
  1. How can I block main UI Thread by MessageBox.Show("test") ?
  2. How can I change text my label from executed code by Quartz?

txtLabel.Text = "new value"; <= this not working because txtLabel don't exists on this class.

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Quartz;

namespace EMoreauDemoQuartzCS
{
    [DisallowConcurrentExecution]
    public class JobWriteToTextFile : IJob
    {
        public static Thread t;
        public void run()
        {
            MessageBox.Show("test");
            txtLabel.Text = "new value";
        }
        public Task Execute(IJobExecutionContext context)
        {

            t = new Thread(run);
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
            return Task.CompletedTask;
        }

    }
}
walen
  • 7,103
  • 2
  • 37
  • 58
DonLeon
  • 11
  • 3
  • I've got no idea what you're trying to do here – Caius Jard May 13 '19 at 05:44
  • I think you might want to look at *Decoupled Messages* or *Event Aggregator*, however, this does seem a little *X/Y'ish* – TheGeneral May 13 '19 at 05:44
  • 2
    You should not update UI controls from the thread. A class that writes text to a file, should not access UI controls. – Jeroen van Langen May 13 '19 at 05:48
  • Possible duplicate of [How to make a Job raise an EventHandler in Quartz.Net?](https://stackoverflow.com/questions/8828722/how-to-make-a-job-raise-an-eventhandler-in-quartz-net) – Circle Hsiao May 13 '19 at 09:00
  • This question is actually quite interesting cause to implement delegate within Job is way difficult than I thought but you should be able to sort it out by study the link above. – Circle Hsiao May 13 '19 at 09:01
  • Another problem you are going to face is you are not able to modify UI by external thread which you can find solution from [How do I update the GUI from another thread?](https://stackoverflow.com/questions/661561/how-do-i-update-the-gui-from-another-thread) – Circle Hsiao May 13 '19 at 09:04

0 Answers0