This project has moved and is read-only. For the latest updates, please go here.

Windows Form Freezes launching from script

Jan 28, 2016 at 9:38 AM
Edited Jan 28, 2016 at 9:39 AM

I am launching windows form from script in event handler, form launched successfully and unable interact with form and form freezes.
            FileSystemWatcher _fileWatcher = new System.IO.FileSystemWatcher();
            vde.AddHostObject("_fileWatcher", _fileWatcher);        
            _fileWatcher.Path = "C:\\Users\\praveen\\Desktop";
            _fileWatcher.Filter = "*.*";
            _fileWatcher.NotifyFilter = System.IO.NotifyFilters.Attributes |
                                                     System.IO.NotifyFilters.CreationTime |
                                                     System.IO.NotifyFilters.DirectoryName |
                                                     System.IO.NotifyFilters.FileName |
                                                     System.IO.NotifyFilters.LastAccess |
                                                     System.IO.NotifyFilters.LastWrite |
                                                     System.IO.NotifyFilters.Security |
            _fileWatcher.EnableRaisingEvents = true;
            _fileWatcher.IncludeSubdirectories = true;
var form=new WinForms.System.Windows.Forms.Form();

var delconncect=_fileWatcher.Created.connect(function(obj,e){

var desconncect=_fileWatcher.Deleted.connect(function(obj,e){
form does not freeze if we launch without event handler.

Thanks and Regards
Praveen Kumar
Jan 28, 2016 at 1:09 PM
Hi Praveen,

The problem is likely that you're showing the form on a worker thread instead of your application's UI thread. Try this:
FileSystemWatcher _fileWatcher = new System.IO.FileSystemWatcher();
vde.AddHostObject("_fileWatcher", _fileWatcher);
// ...
_fileWatcher.SynchronizingObject = someForm; // <-- ADD THIS LINE
where someForm is your application's main form or some other form that's active before you run your script.

Good luck!
Jan 29, 2016 at 5:41 AM

Thank you. it's working.