This project has moved. For the latest updates, please go here.

Windows Form Freezes launching from script

Jan 28, 2016 at 8:38 AM
Edited Jan 28, 2016 at 8:39 AM
Hi,

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 |
                                                     System.IO.NotifyFilters.Size;
            _fileWatcher.EnableRaisingEvents = true;
            _fileWatcher.IncludeSubdirectories = true;
Script
var form=new WinForms.System.Windows.Forms.Form();

var delconncect=_fileWatcher.Created.connect(function(obj,e){
     form.Show();   
});

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

Thanks and Regards
Praveen Kumar
Coordinator
Jan 28, 2016 at 12: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 4:41 AM
Hi,

Thank you. it's working.


Regards
Praveen