Hi
I am running Faxman as a Windows service. I write my own window service to monitor the process of pending fax. My service has a timer (interval = 5sec) which will call Faxman and monitor the status of pending faxes. Everything works fine, but after a day or two, Faxman fails to initialise and thrown the above exception (Error creating window handle). I am running both Faxman Fax Engine and my own windows service when no user is logged in, and the exception only occurs after the service has been running for one or two days. Is it because I keep on creating and disposing the faxman object?
The following console application can help reproduce the problem.
Imports DataTech.FaxManNet
Module Module1
Sub Main()
Dim i As Integer = 0
While True
Dim myFaxMan As New FaxMan()
i = i + 1
If i Mod 100 = 0 Then
Console.WriteLine(i)
End If
myFaxMan.Dispose()
End While
End Sub
End Module
Notice the variable i. Program runs OK for i < 5000. At i = 5000, screen distortion appeared, console window started to move to top left corner of screen and other windows were also affected. At i = 10000, an exceptionof type System.ComponentModel.Win32Exception was thrown: error creating window handle. Task manager (process tabs) shows that the number of window handle increases by several hundreds every time a new faxman object is created (and ends up about 500,000), but those handles are not released after the object is disposed, causing the above overflow.
Exception trace shows:
System.ComponentModel.Win32Exception was unhandled
ErrorCode=-2147467259
Message="Error creating window handle."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at DataTech.FaxManNet.FaxWindow.CreateWindow()
at DataTech.FaxManNet.FaxWindow..ctor(FaxMan fx)
at DataTech.FaxManNet.FaxMan..ctor()
at ConsoleApplication2.Module1.Main() in E:\MyProjects\SEMS\TFServices\ConsoleApplication2\Module1.vb:line 12
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
How do I fix this problem? Thanks.