Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2007

Tip: Looking for answers? Try searching our database.

ApplicationException in TimerBase.AddTimerNative method.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jan Obrestad - 29 Jun 2007 13:02 GMT
Hello.
I'm developing a module in .Net for a program that's made in c++. With a
new version of this program I started getting strange exceptions in my
module.

I found out that the exceptions originated in the AddTimerNative method
of the TimerBase class. Using Reflector I've found out that this is an
unmanaged native method in the framework itself. I'm using .Net 2.0.

I've had two different messages on the ApplicationExceptions:
"Error in the application" (very helpfull....) and "Overlapped I/O
operation is in progress."

Does anyone have some idea what the problem might be?

To clarify, the developers on the main application say they have changed
nothing about how they load and execute .NET modules.

To make things even more confusing, it's not consistent, sometimes I get
 this exception upon starting on the module, other times that works fine.

And these exceptions only show up in release builds of the software, it
suns fine in debug mode on my machine.

Any help in finding out what on earth is happening would be appreciated.

Jan Obrestad
Jan Obrestad - 02 Jul 2007 11:34 GMT
Just to clarify.
I was wrong when I said it runs fine in debug mode. I was running an
older version of the program that do not have this problem. As soon as I
used the new version the debug build also failed.

So I've narrowed the cause down to some change made in the main program,
but this is a large program with many modules so it would be nice if
someone could give a suggestion of what to look for.

> Hello.
> I'm developing a module in .Net for a program that's made in c++. With a
[quoted text clipped - 23 lines]
>
> Jan Obrestad
Jan Obrestad - 24 Sep 2007 07:48 GMT
Some of my colleagues managed to find a solution to this.
The problem was this code from an unmanaged dll that was used by the
program:

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                    )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        g_hModule = (HINSTANCE)hModule;

    case DLL_THREAD_ATTACH:
        CoInitialize(NULL);
        break;
    case DLL_THREAD_DETACH:

    case DLL_PROCESS_DETACH:
        ::CoUninitialize();
        break;
    }
    return TRUE;
}

After this was fixed to
BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                    )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
        g_hModule = (HINSTANCE)hModule;
        break;
    case DLL_THREAD_ATTACH:

        break;
    case DLL_THREAD_DETACH:
        break;
    case DLL_PROCESS_DETACH:

        break;
    }
    return TRUE;
}

the problem was gone.
The problem is calling CoInitialize(NULL) for every new thread.

Hope this might be a help to anyone having the same problem.

> Just to clarify.
> I was wrong when I said it runs fine in debug mode. I was running an
[quoted text clipped - 34 lines]
>>
>> Jan Obrestad

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.