in

Archived Data Techniques Forums

"Error creating window handle" exception while initiatializing Faxman object

Last post 09-18-2007 12:28 PM by MikeS. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 09-16-2007 9:09 PM

    "Error creating window handle" exception while initiatializing Faxman object

    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.

     

  • 09-18-2007 8:32 AM In reply to

    • MikeS
    • Top 25 Contributor
    • Joined on 07-20-2007
    • Posts 39

    Re: "Error creating window handle" exception while initiatializing Faxman object

    Caveat.. I am by no means a VB Expert..
    I ran your test program and do see a problem when the count pass'es 5000.
    Is there a reason you are instantiating the MYFAXMAN object within your while loop?
    Can you not do it outside the loop and only do it once

    I know this was only a test program but even in the actual program I would not think that doing the instantion each loop would be a good idea.

     You also might want to mention the version of Faxman you are developing under.

     

  • 09-18-2007 12:11 PM In reply to

    Re: "Error creating window handle" exception while initiatializing Faxman object

    I am using the latest version of Faxman 4.1.3.0. The actual implementation has a timer which would call the sub-routine processPendingFax() every 5 seconds. The faxman object was re-created and disposed inside processPendingFax() everytime the sub-routine was called, which was simulated in my test program. The reason for this was because processPendingFax and the windows service are in 2 different projects and the Faxman object was put as Private. I changed my code so that the windows service initialises the Faxman object and passes it to processPendingFax(). In this way the Faxman object is created only once, and not on every instance of processPendingFax(), and the problem disappeared!

    Having said that, is this a bug of Faxman, in terms of wasting system resources. Running Microsoft Spy++ (included in Microsoft Visual Studio Tools) will show that a lot of extra window handles are created every time I do a new faxman() and are never released. Task manager also shows that my application's memory consumption increases by several hundreds KB every time a new faxman object is created. This should be fixed in future releases. Disposing the Faxman object by calling faxman.Dispose() should release any system resources previously consumed by Faxman.

  • 09-18-2007 12:28 PM In reply to

    • MikeS
    • Top 25 Contributor
    • Joined on 07-20-2007
    • Posts 39

    Re: "Error creating window handle" exception while initiatializing Faxman object

    Good to hear you have a solution.
    FYI FaxMan SDK V 4.4.3.0 was released a few weeks ago.

    As for this being a bug... I am not sure,  according to my understanding any .DISPOSE (faxman or any other) does not happen immediately.  The Garbage Collection in .NET handle the clean up when the object goes "out of scope"... How fast that happens varies.  There might be something inteferring with that or it could specific with the faxman.dispose.

     

Page 1 of 1 (4 items)
Copyright 2009 Data Techniques, Inc. All Rights Reserved.