Skip to main content

COM threading issue with overlap windows


Problem:  The application sometimes hangs during normal operation. The hang is more prominent in case of more overlap window usage.
.
Analysis: The problem occurred rarely and in some operating systems. There were no clear steps on how and why the hang happens. On debugging the hang dumps from customers site, it pointed to fact that the hang happens while releasing a com object of the process. The application used smart class auto pointers like CComPtr and CComQIPtr for creating and deleting the com objects. On more digging the dump files we could notice that the com object thread where it was created is not available in the dump files. Com objects are created on the thread where we call co-create instance. In case of overlaps opened from the application, each overlap is a different thread. And it is possible to open another overlap from the already opened overlap via context menu. Hence the parent of the new overlap is the first overlap that was opened from the main thread of the application. And this was the trigger for the issue. Sometimes the user may close the parent overlap before closing the child overlap. In that case if the child overlap or parent overlap is being referred by some other thread, for example main thread then it would throw an exception if the com framework tries to destroy an null com object. And this was the case in our hang also, the overlap information is maintained by the main thread for some other functionality. When main thread tries to release the com objects owned by overlap threads, then the application would hang if it tries to release NULL com objects (when the overlap thread dies, it releases all the objects it owns).

Solution: The solution of this issue was to follow the factory design pattern. All the overlap thread creation was passed on to the main thread of the application. Hence the creation and destruction of the threads are fully maintained under the control of the application. Instead of passing the com objects directly between the threads, unique Id of the com objects were passed. The user of this com objects then can use the ID’s of the com object and request the main thread for the com object. Reference handling being managed by the main thread of the process, the life time handling of the com objects thus been taken care. This fixed the issue without breaking any of the existing functionality of the application.

Comments

Popular posts from this blog

Real time data to web application using Microsoft Signal R and Razor Pages

Today we are going to learn how to create razor pages and how to send run time value to the razor page using Signal R Create a new .NET core web application Add Signal R library by,  Add Client-Side Library dialog in the project, for Provider select "unpkg" and select the latest version from the drop down For Library, enter @aspnet/signalr@1, Add a new folder to the project named as Hubs The chat hub class inherits from HUb class that manages connections and messaging The send message is called to send the message to all the clients. MyHub.cs file contains the following code using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR; //using System.Threading.Tasks; namespace SignalRSample.Hubs {     public class MyHub : Hub     {         public async Task SendMessage(string user, string message)         {       ...

CRUD operation with WCF service and WPF client

 The database restored on local server WCF Service is talking to the database. Used Visual Studio 2019, entity framework 6 for data base operations from the service. The service exposes the following API’s.  The WCF contracts has both synchronous and asynchronous API's The client is in WPF. It has three windows, main window, customer window and order window as follows. The client uses the WCF service for database operations. When customer button is clicked, the customer window is displayed as below. We can perform CRUD operation from it. The customer can be searched based on ID. New customer window The order button launched order window. It has combo box to choose the customer ID. On selecting the ID, the order details are displayed in the data grid as follows. The source code is available in the GIT hub, URL below: https://github.com/SwagatikaGoswami/WPF_WCF_CRUD.git

Online Exam App with .NET Core Web API and Blazor Client

 We will develop an app that can host online exam. It will have the feature to register user, allow the user to log in. Dashboard for creating sample tests.  The code is shared in GIT hub repository https://github.com/ SwagatikaGoswami/ OnlineExamApp.git The database is MySQL database. The server is a WEB API .NET Core service that uses entity framework for DB operations. The client is a web assembly blazor application. The password stored in the database is encrypted. Register window is as follows. It checks for the mandatory fields. The log in page is as follows: The admin dashboard after logging in  The admin dashboard when new test button is clicked. It uses a Blazor component for adding new test samples.