masteramoebe 0 Posted August 1, 2015 Share Posted August 1, 2015 hi there, like the title says i would like to instantiate a Windows.Form object in a Custom Profile. i tried it in an backgroundworker thread but it still freezes the wrobot and crashes. any idea how i could do this ? best regards Link to comment https://wrobot.eu/forums/topic/2292-windowsform-in-custom-profile/ Share on other sites More sharing options...
Droidz 2738 Posted August 2, 2015 Share Posted August 2, 2015 Hello, Try it: using System.Threading; using System.Windows.Forms; using Custom_Profile; public class CustomProfile : ICustomProfile { private Form _form; private bool _isStarted; public void Pulse() { _isStarted = true; var t = new Thread(OpenWinform); t.SetApartmentState(ApartmentState.STA); t.Start(); } public void Dispose() { _isStarted = false; if (_form != null) { // Use BeginInvoke because it not called from winform thread. _form.BeginInvoke(new MethodInvoker(_form.Close)); _form.BeginInvoke(new MethodInvoker(_form.Dispose)); } } void OpenWinform() { _form = new Form(); _form.Controls.Add(new Label { Text = "My window" }); _form.ShowDialog(); } } Link to comment https://wrobot.eu/forums/topic/2292-windowsform-in-custom-profile/#findComment-10660 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now