Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Unassigned: ClearScript, C# and Scheduler [103]

$
0
0
Context: Azure, C#, ClearScript.V8.5.4.5

I have a number of C# programs running under the scheduler in an Azure VM. All but two are currently working due to an error which identifies itself by a last run result of 0xE0434352.

In Event Viewer -> Windows Logs -> Application there are a number of errors listed, all of which say mostly the same as the following

```
Application: NormanEmailHandler.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.ComponentModel.Win32Exception at MS.Win32.UnsafeNativeMethods.RegisterClassEx(WNDCLASSEX_D) at MS.Win32.HwndWrapper..ctor(Int32, Int32, Int32, Int32, Int32, Int32, Int32, System.String, IntPtr, MS.Win32.HwndWrapperHook[]) at System.Windows.Threading.Dispatcher..ctor() at System.Windows.Threading.Dispatcher.get_CurrentDispatcher() at Microsoft.ClearScript.Windows.WindowsScriptEngine..ctor(System.String, System.String, Microsoft.ClearScript.Windows.WindowsScriptEngineFlags) at Microsoft.ClearScript.Windows.JScriptEngine..ctor(System.String, System.String, Microsoft.ClearScript.Windows.WindowsScriptEngineFlags) at Microsoft.ClearScript.Windows.JScriptEngine..ctor(Microsoft.ClearScript.Windows.WindowsScriptEngineFlags) at NormanEmailHandler.Program..cctor() Exception Info: System.TypeInitializationException at NormanEmailHandler.Program.Main(System.String[])
```

I have looked at and tried the code samples at [AppDomain.UnhandledException Event](https://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception(v=vs.71).aspx) however the EXE fails before that code gets executed, even when it's the first thing encountered in the Main().

It does occur to me as I write this that instantiating the object before Main() kicks in might have something to do with the exception handler not firing. What's be nice, though would be to know why I'm having the problem at all.

```
namespace NormanEmailHandler
{
class Program
{
static JScriptEngine JSengine = new JScriptEngine(WindowsScriptEngineFlags.EnableDebugging | WindowsScriptEngineFlags.EnableJITDebugging);

```

Comments: Hmm, if restarting the VM fixed the issue, then Win32 resource exhaustion is the likely culprit, just like in the discussion linked above. If the issue returns, we'd love to know the `Win32Exception` error code. Windows script engines have thread affinity. That is, not only are they unsafe for concurrent use, but each instance can only be used on the thread that created it. ClearScript uses .NET's [Dispatcher class](https://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher(v=vs.110).aspx) (which apparently uses Win32 window handles under the covers) to enforce this restriction and route event callbacks to the appropriate thread; all WPF controls use the same facility. The script control's `AllowUI` property lets the host block message boxes, but it doesn't affect the script engine's thread affinity.

Viewing all articles
Browse latest Browse all 2297

Latest Images

Trending Articles





Latest Images