473,513 Members | 2,469 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 4945
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********@yahoo.com> wrote in message
news:57**************************@posting.google.c om...
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.BeginInvoke.

Willy.

"Paul" <pk********@yahoo.com> wrote in message
news:57**************************@posting.google.c om...
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.brExecute(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 DelegateAddString(String s);

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

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

// initialize delegates
m_DelegateAddString = new DelegateAddString(this.AddLineToOutput);
}

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

private void button1_Click(object sender, System.EventArgs e)
{

Work work = new Work(this);
ThreadStart threadDelegate = new ThreadStart(work.QueryTest);
Thread newThread = new Thread(threadDelegate);
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.Reflection.Missing.Value;
D3CLODBC.clsD3Environment m_Env = null;
D3CLODBC.clsD3Connection m_Con = null;
D3CLODBC.clsD3TclCommand m_Tcl;

//initilize the connection
m_Env = new D3CLODBC.clsD3EnvironmentClass();
m_Con = m_Env.brOpenConnection("ODBC","members_test");
msg = "Connected...";

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

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

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

//returning string of stuff
msg = m_Tcl.brCapturing.get_brCString();
mainForm.Invoke(mainForm.m_DelegateAddString,new object[]{msg});
}

}

}
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message news:<OW*************@TK2MSFTNGP12.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.BeginInvoke.

Willy.

Nov 16 '05 #4

"Paul" <pk********@yahoo.com> wrote in message
news:57**************************@posting.google.c om...
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.brExecute(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 DelegateAddString(String s);

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

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

// initialize delegates
m_DelegateAddString = new DelegateAddString(this.AddLineToOutput);
}

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

private void button1_Click(object sender, System.EventArgs e)
{

Work work = new Work(this);
ThreadStart threadDelegate = new ThreadStart(work.QueryTest);
Thread newThread = new Thread(threadDelegate);
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.Reflection.Missing.Value;
D3CLODBC.clsD3Environment m_Env = null;
D3CLODBC.clsD3Connection m_Con = null;
D3CLODBC.clsD3TclCommand m_Tcl;

//initilize the connection
m_Env = new D3CLODBC.clsD3EnvironmentClass();
m_Con = m_Env.brOpenConnection("ODBC","members_test");
msg = "Connected...";

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

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

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

//returning string of stuff
msg = m_Tcl.brCapturing.get_brCString();
mainForm.Invoke(mainForm.m_DelegateAddString,new object[]{msg});
}

}

}


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

....
newThread.ApartmentState = 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.ApartmentState = 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********@yahoo.com> wrote in message
news:57**************************@posting.google.c om...
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.ApartmentState = 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*************@tk2msftngp13.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********@yahoo.com> wrote in message
news:57**************************@posting.google.c om...
Willy,
I used oleview and the Threadingmodel is "None"

Peter

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:<u2*************@tk2msftngp13.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**************@TK2MSFTNGP12.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
Hi Paul,

"> 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?


Take a look at remoting.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com
Nov 16 '05 #11

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

Similar topics

0
1728
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...
2
1919
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...
0
1140
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...
1
1920
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...
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...
0
2661
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...
4
1703
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...
0
2590
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" -...
2
1644
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
3055
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...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7162
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7527
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
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,...
1
5090
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3234
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...
0
1597
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 ...
1
803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
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...

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.