SOLVED Open a GeModalDialog from a Job Observer

Hello,

I read this thread about ObservableFinished(), and it works fine so far: I have all the data I need in my result struct, and it's available in the Lambda I pass to AddObserver().

However, when my job is finished, I want to display a GeModalDialog. Opening a simple OS message box with GeOutString() works fine. But when I instead try to open a custom dialog, nothing happens.

Here's the code:

// Create job
auto checkForUpdate = CheckForUpdateJob::Create() iferr_return;
checkForUpdate.ObservableFinished().AddObserver([checkForUpdate]() -> maxon::Result<void>
																								{
	iferr_scope;

	// Get job's result. this works fine.
	MyResultStruct result = checkForUpdate.GetResult() iferr_return;
	if (result.updateAvailable)
	{
		// This works:
		if (GeOutString(GeLoadString(IDS_UPDATECHECK_RESULT_AVAILABLE), GEMB::YESNO) == GEMB_R::V_YES)
		{
			DoSomething();
		}

		// This does not work:
		MyModalDialog theDialog;
		theDialog.Open();
	}
	return maxon::OK;
}) iferr_return;

// Enqueue job
checkForUpdate.Enqueue();

Why is a GeModalDialog not working? And how can I make it work?

Thanks in advance,
greetings,
Frank

hi,

That's because you are not in the main thread. So i would use maxon::ExecuteOnMainThread to open the GeDialog.
I don't have memory leak but maybe with a more complexe example you could end up with some. Be aware of that.

checkForUpdate.ObservableFinished().AddObserver([checkForUpdate]() -> maxon::Result<void>
		{
			iferr_scope;
			// Get job's result. this works fine.
			HttpResponse result = checkForUpdate.GetResult() iferr_return;
			if (result.updateAvailable)
			{
				// This works:
			if (GeOutString("hello"_s, GEMB::YESNO) == GEMB_R::V_YES)
				{
					// DoSomething();
				ApplicationOutput("hello");
				}

			maxon::ExecuteOnMainThread([]()
			{
					MyModalDialog theDialog;
					theDialog.Open(DLG_TYPE::MODAL, 123456);
			}, false); // false here so we don't wait the dialog to be closed.
			ApplicationOutput("thread is going away");
			}
			return maxon::OK;
		}) iferr_return;

Cheers,
Manuel

Oh, that sounds like an idea! I'll check that out, thanks!

So, if GUI stuff is not permitted in threads other than the main thread, should even OS dialogs like GeOutString() not be used in a threaded context? Yes, it works, but is it a good idea?

Thanks & greetings,
Frank

It works perfectly, thanks again!

Cheers,
Frank