Posted by Christian Klauser on 2007-06-26 01:10 CET
(In reply to: Re: Want to sell copies of Champ?
posted by Christian Klauser on 2007-06-18 17:01 CET)
|
Hi, while waiting for your reply, I've done some research. The results are quite promising: * void ChampMain() * { * * var win = new Window(); * * win.Run(); * * * * WaitFor(win.button,"Click"); * * * * win.label.Text = "Thanks for clicking.\nNow enter your name:"; * * win.button.Enabled = false; * * win.textBox.Text = ""; * * win.textBox.Enabled = true; * * * * do * * { * * * var key = WaitFor<KeyEventArgs>(win.textBox,"KeyDown"); * * * if (key.KeyCode == Keys.Enter) * * * * break; * * * win.label.Text = "Close by pressing <Enter>."; * * } while (true); * * * * win.Close(); * } (Yes, I used the C# 3.0 compiler, thus the implicitly typed 'var's, but the application is compiled against the .NET Framework 2.0) Using the static 'T WaitFor<T>(object,string) where T : EventArgs' method, you can block the execution of the current thread until the requested event has been raised. If the event's signature follows the .NET event pattern (2 parameters: object sender, EventArgs e), the function returns the EventArgs passed to the dynamically generated handler. For my sample application, I used 3 managed threads: - MAIN: runs "ChampMain" - RENDER: processes the windows message loop - ROUTER: routes events from the RENDER thread to the MAIN one There, however, are scenarios that cannot be handled sequentially. The Form.Close event allows it's handlers to prevent the window from closing, but since the 'handler' (in the sequential model) only signals the MAIN thread to continue, the latter can not deterministically influence the window's decision whether to close or not: Once all event handlers have been invoked, the window checks the EventArgs object. The MAIN thread may or may not have been fast enough to make changes to that object. Add * using System; * using System.Collections.Generic; * using System.Windows.Forms; * * namespace SequentialWindow * { * * partial class Program : SequentialProgram * * { to the code snippet above and you have what users of a champ-to-.NET-port would see. (The "using System.Windows.Forms;" is required for the 'KeyEventArgs' and the 'Keys' enumeration) The 'partial' keyword merges the users class with a file that would be part of a Champ project template and that defines a 'public static void Main()' in which it sets up the event router and instantiates 'Program' (so programming novices are not confronted with 'static'). I would say: Champ on the .NET platform is definitely not impossible. |
| Email: (hidden) |
|
Copyright © 2010 Salvisberg Software & Consulting. All rights reserved. |
Top |