473,673 Members | 2,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UI freezes

Hi Guys,
I have an application which uses COM object to connect to a "pick"
database.
With this object I can run some select statemnts, however when the
select command is send to the server, my UI freezes and waits for the
connection to return result.
I tried to run the command in separate thread but with no improvement.
Any suggestions are greatly welcomed.
Thanks.
Nov 16 '05 #1
10 4955
Hi Paul,

If you run commands in separate thread it shouldn't freeze the UI.
Can you show us a snippet of the code?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"Paul" <pk********@yah oo.com> wrote in message
news:57******** *************** ***@posting.goo gle.com...
Hi Guys,
I have an application which uses COM object to connect to a "pick"
database.
With this object I can run some select statemnts, however when the
select command is send to the server, my UI freezes and waits for the
connection to return result.
I tried to run the command in separate thread but with no improvement.
Any suggestions are greatly welcomed.
Thanks.

Nov 16 '05 #2
Make sure your separate thread is initialized to run in an STA, if you
don't, your COM object will still run on the UI (STA)thread.
Also note that you shouldn't directly update the UI elements from this
thread, you have to call Control.Invoke or Control.BeginIn voke.

Willy.

"Paul" <pk********@yah oo.com> wrote in message
news:57******** *************** ***@posting.goo gle.com...
Hi Guys,
I have an application which uses COM object to connect to a "pick"
database.
With this object I can run some select statemnts, however when the
select command is send to the server, my UI freezes and waits for the
connection to return result.
I tried to run the command in separate thread but with no improvement.
Any suggestions are greatly welcomed.
Thanks.

Nov 16 '05 #3
Here is a part of the code. I included only main parts which deal with
this issue. I hope it will give you a picture what I'm trying to do.
The part which takes long time is "m_Tcl.brExecut e(oMs,oMs);"

Question for Willy:
You mentioned to run the thread in an STA. Could you please send me
some sample of this?
Thanks
Paul

namespace Pick_Query
{
#region Public Delegates

// delegates used to call MainForm functions from worker thread
public delegate void DelegateAddStri ng(String s);

#endregion
/// <summary>
/// Summary description for MainForm.
/// </summary>

public class MainForm : System.Windows. Forms.Form
{
public MainForm()
{
InitializeCompo nent();

// initialize delegates
m_DelegateAddSt ring = new DelegateAddStri ng(this.AddLine ToOutput);
}

[STAThread]
static void Main()
{
Application.Run (new MainForm());
}

private void button1_Click(o bject sender, System.EventArg s e)
{

Work work = new Work(this);
ThreadStart threadDelegate = new ThreadStart(wor k.QueryTest);
Thread newThread = new Thread(threadDe legate);
newThread.Name = "test thread...";
newThread.Start ();
}
}

public class Work
{
MainForm mainForm;
public Work(MainForm mform)
{
mainForm = mform;
}
public void QueryTest()
{
string msg;
object oMs = System.Reflecti on.Missing.Valu e;
D3CLODBC.clsD3E nvironment m_Env = null;
D3CLODBC.clsD3C onnection m_Con = null;
D3CLODBC.clsD3T clCommand m_Tcl;

//initilize the connection
m_Env = new D3CLODBC.clsD3E nvironmentClass ();
m_Con = m_Env.brOpenCon nection("ODBC", "members_test") ;
msg = "Connected. ..";

//send message to the MainForm
mainForm.Invoke (mainForm.m_Del egateAddString, new object[]{msg});

//command to be executed on the D3 server
string cmd = "pq_sort_ta b solicitor a1 a2 a3 a4 a5";
m_Tcl = m_Con.brOpenTcl Command(cmd);

// this is the part which takes long time
m_Tcl.brExecute (oMs,oMs); //executing the command

//returning string of stuff
msg = m_Tcl.brCapturi ng.get_brCStrin g();
mainForm.Invoke (mainForm.m_Del egateAddString, new object[]{msg});
}

}

}
"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message news:<OW******* ******@TK2MSFTN GP12.phx.gbl>.. .
Make sure your separate thread is initialized to run in an STA, if you
don't, your COM object will still run on the UI (STA)thread.
Also note that you shouldn't directly update the UI elements from this
thread, you have to call Control.Invoke or Control.BeginIn voke.

Willy.

Nov 16 '05 #4

"Paul" <pk********@yah oo.com> wrote in message
news:57******** *************** ***@posting.goo gle.com...
Here is a part of the code. I included only main parts which deal with
this issue. I hope it will give you a picture what I'm trying to do.
The part which takes long time is "m_Tcl.brExecut e(oMs,oMs);"

Question for Willy:
You mentioned to run the thread in an STA. Could you please send me
some sample of this?
Thanks
Paul

namespace Pick_Query
{
#region Public Delegates

// delegates used to call MainForm functions from worker thread
public delegate void DelegateAddStri ng(String s);

#endregion
/// <summary>
/// Summary description for MainForm.
/// </summary>

public class MainForm : System.Windows. Forms.Form
{
public MainForm()
{
InitializeCompo nent();

// initialize delegates
m_DelegateAddSt ring = new DelegateAddStri ng(this.AddLine ToOutput);
}

[STAThread]
static void Main()
{
Application.Run (new MainForm());
}

private void button1_Click(o bject sender, System.EventArg s e)
{

Work work = new Work(this);
ThreadStart threadDelegate = new ThreadStart(wor k.QueryTest);
Thread newThread = new Thread(threadDe legate);
newThread.Name = "test thread...";
newThread.Start ();
}
}

public class Work
{
MainForm mainForm;
public Work(MainForm mform)
{
mainForm = mform;
}
public void QueryTest()
{
string msg;
object oMs = System.Reflecti on.Missing.Valu e;
D3CLODBC.clsD3E nvironment m_Env = null;
D3CLODBC.clsD3C onnection m_Con = null;
D3CLODBC.clsD3T clCommand m_Tcl;

//initilize the connection
m_Env = new D3CLODBC.clsD3E nvironmentClass ();
m_Con = m_Env.brOpenCon nection("ODBC", "members_test") ;
msg = "Connected. ..";

//send message to the MainForm
mainForm.Invoke (mainForm.m_Del egateAddString, new object[]{msg});

//command to be executed on the D3 server
string cmd = "pq_sort_ta b solicitor a1 a2 a3 a4 a5";
m_Tcl = m_Con.brOpenTcl Command(cmd);

// this is the part which takes long time
m_Tcl.brExecute (oMs,oMs); //executing the command

//returning string of stuff
msg = m_Tcl.brCapturi ng.get_brCStrin g();
mainForm.Invoke (mainForm.m_Del egateAddString, new object[]{msg});
}

}

}


No sample needed, just set the ApartmentState property to STA before
starting the thread.

....
newThread.Apart mentState = ApartmentState. STA;
newThread.Start ();
.....

As a result you'll have two threads running - the UI and the secondary
thread - each in their own apartment. The COM object will run in the
secondary thread, so no marshalling is required when calling it's methods
from the managed code.

Willy.
Nov 16 '05 #5
Willy,
thanks for the reply. I tried that and the UI is still freezing and waiting
for the call to execute the command to finish, after that it becomes responsive.

I'm out of ideas and open to all sugestions.
Thanks again,
Paul
No sample needed, just set the ApartmentState property to STA before
starting the thread.

...
newThread.Apart mentState = ApartmentState. STA;
newThread.Start ();
....

As a result you'll have two threads running - the UI and the secondary
thread - each in their own apartment. The COM object will run in the
secondary thread, so no marshalling is required when calling it's methods
from the managed code.

Willy.

Nov 16 '05 #6
Paul,
Could you please chack the COM objects "threadingmodel " attribute in the
registry (or using oleview).

Willy.
"Paul" <pk********@yah oo.com> wrote in message
news:57******** *************** ***@posting.goo gle.com...
Willy,
thanks for the reply. I tried that and the UI is still freezing and
waiting
for the call to execute the command to finish, after that it becomes
responsive.

I'm out of ideas and open to all sugestions.
Thanks again,
Paul
No sample needed, just set the ApartmentState property to STA before
starting the thread.

...
newThread.Apart mentState = ApartmentState. STA;
newThread.Start ();
....

As a result you'll have two threads running - the UI and the secondary
thread - each in their own apartment. The COM object will run in the
secondary thread, so no marshalling is required when calling it's methods
from the managed code.

Willy.

Nov 16 '05 #7
Willy,
I used oleview and the Threadingmodel is "None"

Peter

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message news:<u2******* ******@tk2msftn gp13.phx.gbl>.. .
Paul,
Could you please chack the COM objects "threadingmodel " attribute in the
registry (or using oleview).

Willy.

Nov 16 '05 #8
This is something I was afraid of, looks like you have a real problem now.
A COM object that is marked "None" for it's threadingmodel, is a bad thing
especially in the multithreaded world of .NET and Windows Forms.
The object author indicated by this (maybe not intentional) that this
component was not threading aware.
Can't you contact the vendor and ask for something more .NET/COM friendly.

Willy.

"Paul" <pk********@yah oo.com> wrote in message
news:57******** *************** ***@posting.goo gle.com...
Willy,
I used oleview and the Threadingmodel is "None"

Peter

"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message
news:<u2******* ******@tk2msftn gp13.phx.gbl>.. .
Paul,
Could you please chack the COM objects "threadingmodel " attribute in the
registry (or using oleview).

Willy.

Nov 16 '05 #9
"Willy Denoyette [MVP]" <wi************ *@pandora.be> wrote in message news:<OX******* *******@TK2MSFT NGP12.phx.gbl>. ..
This is something I was afraid of, looks like you have a real problem now.
A COM object that is marked "None" for it's threadingmodel, is a bad thing
especially in the multithreaded world of .NET and Windows Forms.
The object author indicated by this (maybe not intentional) that this
component was not threading aware.
Can't you contact the vendor and ask for something more .NET/COM friendly.

Willy.


Thanks Willy,
unfortunatelly I can't. I was thinking maybe I should run a separate
program(exe) for this which would run in the background and it
wouldn't matter if it hanged for
while. Is there an easy way how to pass stuff between two independent
programs?

Thanks again,
Peter
Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1734
by: Enterprise | last post by:
Hi, I use Access 2000. FEBE design. Tables on server, and everything else on local machine. I have 1 table with a primary key ID field and a text field with names in it. This table is like a translator. I have a form that gets a text field from another table with numbers seperated by commas. The form translates this using the translator table and a module. So like 99,34,23, will be translated to bob,mary,tom,. Again, 99 34 and 23 are from...
2
1923
by: FMR | last post by:
I have an Access 2000 application that has a backend database which sits on the network and a frontend installed to each PC. When the frontend is opened, users have to log on and then the database opens their menu form with buttons for key activities. The problem I am having is that the user is logging on then there is a delay before the menu form opens (normally this is really fast) and then the application freezes - they can't push...
0
1148
by: CLarkou | last post by:
I developed an Access 2003 program. When first form opens, part of form freezes, for example I have 5 buttons on form, 4 of them behave like pictures (you click on them, but they don't get pressed), while 5th button can be clicked. If you double-click on windows taskbar, then you can click on all 5 buttons. What could be the problem ?
1
1926
by: Yahya Saad | last post by:
Dear All, I have upgraded and application I developed on VB6 which uses the Mscomm1 component and reads from COM1 port data send, then sends these records to a table in SQL 2000. I upgraded the application to VB.Net windows form to use the try catch method of trapping errors, the form runs smoothly but after about 10 minutes the form freezes without raising any error. Any hints will be useful.
0
849
by: Daniel | last post by:
C# windows service freezes on System.Diagnostics.Process.Start(info) When I launch PSCP from a C# windows service and launch pscp 0.53 there are no issues. but when I use C# windows service to launch pscp 0.58 C# freezes in System.Diagnostics.Process.Start(info)? pscp 0.58 works fine at command line, but causes C# to freeze on ystem.Diagnostics.Process.Start(info) also i noticed that the pscp process does not show in taske manager while...
0
2691
by: genojoe | last post by:
I am running an application that, when not used, just sits there firing a BackgroundWorker every 20 seconds. Every now and then, the BackgroundWorker freezes between the DoWork and RunWorkerCompleted procedures. My simplified procedures are shown below. They endlessly write messages to a text file. At some point it never moves from DoWork to RunWorkerCompleted. I do have services such as Outlook and Norton SystemWorks running in the...
4
1709
by: genojoe | last post by:
My development computer (1 gig, XP Home Edition SP2) freezes when I am editing a very large VB.NET project. It can take minutes to move between a code pane and the Find and Replace pane. On occasion, it freezes for one or more hours no matter what I do. I would go back to an earlier version of VS but I have already invested too much time incorporating features that only exist in VS 2005. I have installed the HotFix but it did not do...
0
2603
by: Marcin Szarek | last post by:
Hi! For a few months we suffer mysterious problem with Oracle 10g RAC (more details on server configuration at the bottom). At regular basis (every 5 minutes) nodes of our cluster "freeze" - during couple of seconds operating system for some mysterious reason does nothing - as far as we're concerned - in userspace. Every single userspace process stops for this period. After a few seconds system comes back to life and all suspended...
2
1655
by: =?Utf-8?B?dG9ueSBsb2Nr?= | last post by:
Has anybody else noticed that this webpage freezes when viewed with IE7 on a wide screen (1920*1200) when IE7 is maximised. Or is it just me, using Vista Ultimate by the way.
1
3084
by: xfroggy | last post by:
Alright guys, If someone could give me some ideas or examples if possible since I'm really stuck on this one without a clue how to proceed. I'm trying to write a little logging program for my scanner, but I'm stuck with infinite loop. Still new to programming, but I got myself to dead end. I want my program to have infinite loop when I press the toggle button and the info to display in labels in my gui. I got that by clicking a button, but...
0
8953
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8855
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8652
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7487
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4254
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2853
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1852
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.