473,412 Members | 4,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Timed UI Updates in Compact Framework

Hi,
I have an application running on a PocketPC written in
C#. The app collects information from the user and also
does database connections periodically with a seperate
background thread. I'm hoping to display the status of
this background thread
(IE: "Connecting", "Downloading", "Disconnected") to the
user via a statusBar.

To keep the background thread and user-interface threads
seperate, I have a 'Status' property in the background
thread that I would like the UI to occasionally check.

To try it out, I created a System.Threading.Timer in the
UI (Form1) thread and had it run an 'Update' function
that changes the statusBar.Text property to the current
time. Unfortunately, this seemed to partially freeze the
application. I put a MessageBox before the
statusbar.text update and found that the function
continues to be called but the thread stops when it hits
the statusBar property.

I tried the same code in a non pocketPC environment (just
a regular C# application for winxp) and it works fine.

I was wondering what's up with the PocketPC UI threading
that would make it behave this way.

Any help much appreciated.
Nov 22 '05 #1
4 2210
Here's the general code I'm referring to for the simple
statusbar time update example...

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.StatusBar statusBar1;
private System.Threading.Timer statusTimer;

public Form1()
{
InitializeComponent();

statusTimer = new System.Threading.Timer(new
System.Threading.TimerCallback(StatusUpdate), null, 0,
15000);
}

private void StatusUpdate(object pass)
{
MessageBox.Show("Show This");
statusBar1.Text = DateTime.Now.ToString() + "*";
}
}

If you run something like this on a pocketpc you'll
get "Show This" boxes but after you click the first one
(or so) the status bar stops changing...

Thanks for the help...

-----Original Message-----
Hi,
I have an application running on a PocketPC written in
C#. The app collects information from the user and also
does database connections periodically with a seperate
background thread. I'm hoping to display the status of
this background thread
(IE: "Connecting", "Downloading", "Disconnected") to the
user via a statusBar.

To keep the background thread and user-interface threads
seperate, I have a 'Status' property in the background
thread that I would like the UI to occasionally check.

To try it out, I created a System.Threading.Timer in the
UI (Form1) thread and had it run an 'Update' function
that changes the statusBar.Text property to the current
time. Unfortunately, this seemed to partially freeze theapplication. I put a MessageBox before the
statusbar.text update and found that the function
continues to be called but the thread stops when it hits
the statusBar property.

I tried the same code in a non pocketPC environment (justa regular C# application for winxp) and it works fine.

I was wondering what's up with the PocketPC UI threading
that would make it behave this way.

Any help much appreciated.
.

Nov 22 '05 #2
You are modifying a property of the UI outside the main thread, and this is
bad (I think it's just a case that it works on a non pocket pc environment).
You should invoke it through the Invoke method provided by the Form class.

Here is the right code

private void StatusUpdate(object pass)
{
this.Invoke(new Delegate(this.StatusUpdateUIThread));
}

private void StatusUpdateUIThread()
{
statusBar1.Text = DateTime.Now.ToString() + "*";
}

GV
<an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
Here's the general code I'm referring to for the simple
statusbar time update example...

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.StatusBar statusBar1;
private System.Threading.Timer statusTimer;

public Form1()
{
InitializeComponent();

statusTimer = new System.Threading.Timer(new
System.Threading.TimerCallback(StatusUpdate), null, 0,
15000);
}

private void StatusUpdate(object pass)
{
MessageBox.Show("Show This");
statusBar1.Text = DateTime.Now.ToString() + "*";
}
}

If you run something like this on a pocketpc you'll
get "Show This" boxes but after you click the first one
(or so) the status bar stops changing...

Thanks for the help...

-----Original Message-----
Hi,
I have an application running on a PocketPC written in
C#. The app collects information from the user and also
does database connections periodically with a seperate
background thread. I'm hoping to display the status of
this background thread
(IE: "Connecting", "Downloading", "Disconnected") to the
user via a statusBar.

To keep the background thread and user-interface threads
seperate, I have a 'Status' property in the background
thread that I would like the UI to occasionally check.

To try it out, I created a System.Threading.Timer in the
UI (Form1) thread and had it run an 'Update' function
that changes the statusBar.Text property to the current
time. Unfortunately, this seemed to partially freeze

the
application. I put a MessageBox before the
statusbar.text update and found that the function
continues to be called but the thread stops when it hits
the statusBar property.

I tried the same code in a non pocketPC environment

(just
a regular C# application for winxp) and it works fine.

I was wondering what's up with the PocketPC UI threading
that would make it behave this way.

Any help much appreciated.
.

Nov 22 '05 #3
Thanks for the tip and comments on the UI. I knew about
the general UI guidelines for not updating controls
through a second thread but was a little confused by the
Timer threads and then how it worked in regular WinXP.
Good to know about the Invoke method.

BUT, I'm still having a problem. I tried your code
change, except I added:

the public member
public delegate void MyMethod();
and changed the Invoke line to: this.Invoke(new MyMethod(this.StatusUpdateUIThread));
instead of 'new Delegate' since I got compilation errors
the other way.

With these changes I am still running into problems,
though. When the invoke method is called I get 'a
Managed ArgumentException' error that stops the program.
I'm not too familiar with using Invoke so perhaps someone
could let me know where I'm off. With windows XP I
solved the problem by putting the initial timer creation
code in the Form_Load event instead of the form
constructor (I got an error telling me that the window
did not yet have a handle created).

With PocketPC I only get that managed ArgumentException
error. It is related to the use of the Invoke/delegate
and not the statusbar property (it still gives an error
if I comment out the statusbar.text line.

Thanks again for all the help!

- Z

-----Original Message-----
You are modifying a property of the UI outside the main thread, and this isbad (I think it's just a case that it works on a non pocket pc environment).You should invoke it through the Invoke method provided by the Form class.
Here is the right code

private void StatusUpdate(object pass)
{
this.Invoke(new Delegate(this.StatusUpdateUIThread));
}

private void StatusUpdateUIThread()
{
statusBar1.Text = DateTime.Now.ToString() + "*";
}

GV
<an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
Here's the general code I'm referring to for the simple
statusbar time update example...

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.StatusBar statusBar1;
private System.Threading.Timer statusTimer;

public Form1()
{
InitializeComponent();

statusTimer = new System.Threading.Timer(new
System.Threading.TimerCallback(StatusUpdate), null, 0,
15000);
}

private void StatusUpdate(object pass)
{
MessageBox.Show("Show This");
statusBar1.Text = DateTime.Now.ToString() + "*";
}
}



If you run something like this on a pocketpc you'll
get "Show This" boxes but after you click the first one
(or so) the status bar stops changing...

Thanks for the help...

>-----Original Message-----
>Hi,
>I have an application running on a PocketPC written in
>C#. The app collects information from the user and also >does database connections periodically with a seperate
>background thread. I'm hoping to display the status of >this background thread
>(IE: "Connecting", "Downloading", "Disconnected") to the >user via a statusBar.
>
>To keep the background thread and user-interface threads >seperate, I have a 'Status' property in the background
>thread that I would like the UI to occasionally check.
>
>To try it out, I created a System.Threading.Timer in the >UI (Form1) thread and had it run an 'Update' function
>that changes the statusBar.Text property to the current >time. Unfortunately, this seemed to partially freeze

the
>application. I put a MessageBox before the
>statusbar.text update and found that the function
>continues to be called but the thread stops when it hits >the statusBar property.
>
>I tried the same code in a non pocketPC environment

(just
>a regular C# application for winxp) and it works fine.
>
>I was wondering what's up with the PocketPC UI threading >that would make it behave this way.
>
>Any help much appreciated.
>
>
>.
>

.

Nov 22 '05 #4
AHA. I finally found the answer!

On PocketPCs you can't create custom delegates,
apparently. I found this little tidbit:
http://msdn.microsoft.com/mobility/p...nfo/devtools/n
etcf/FAQ/#7.10

So, instead of a 'new Delegate' or 'new MyMethod' I had
to make a 'new EventHandler'. Now it seems to be working.

Hope this doesn't cause everyone else as much wasted time
as it did me.

have a good one,
- Z
-----Original Message-----
Thanks for the tip and comments on the UI. I knew about
the general UI guidelines for not updating controls
through a second thread but was a little confused by the
Timer threads and then how it worked in regular WinXP.
Good to know about the Invoke method.

BUT, I'm still having a problem. I tried your code
change, except I added:

the public member
public delegate void MyMethod();
and changed the Invoke line to: this.Invoke(new MyMethod(this.StatusUpdateUIThread));instead of 'new Delegate' since I got compilation errors
the other way.

With these changes I am still running into problems,
though. When the invoke method is called I get 'a
Managed ArgumentException' error that stops the program.I'm not too familiar with using Invoke so perhaps someonecould let me know where I'm off. With windows XP I
solved the problem by putting the initial timer creation
code in the Form_Load event instead of the form
constructor (I got an error telling me that the window
did not yet have a handle created).

With PocketPC I only get that managed ArgumentException
error. It is related to the use of the Invoke/delegate
and not the statusbar property (it still gives an error
if I comment out the statusbar.text line.

Thanks again for all the help!

- Z

-----Original Message-----
You are modifying a property of the UI outside the main

thread, and this is
bad (I think it's just a case that it works on a non

pocket pc environment).
You should invoke it through the Invoke method provided

by the Form class.

Here is the right code

private void StatusUpdate(object pass)
{
this.Invoke(new Delegate(this.StatusUpdateUIThread));
}

private void StatusUpdateUIThread()
{
statusBar1.Text = DateTime.Now.ToString() + "*";
}

GV
<an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
Here's the general code I'm referring to for the simple statusbar time update example...

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.StatusBar statusBar1;
private System.Threading.Timer statusTimer;

public Form1()
{
InitializeComponent();

statusTimer = new System.Threading.Timer(new
System.Threading.TimerCallback(StatusUpdate), null, 0,
15000);
}

private void StatusUpdate(object pass)
{
MessageBox.Show("Show This");
statusBar1.Text = DateTime.Now.ToString() + "*";
}
}



If you run something like this on a pocketpc you'll
get "Show This" boxes but after you click the first one (or so) the status bar stops changing...

Thanks for the help...
>-----Original Message-----
>Hi,
>I have an application running on a PocketPC written in >C#. The app collects information from the user and

also >does database connections periodically with a seperate >background thread. I'm hoping to display the statusof >this background thread
>(IE: "Connecting", "Downloading", "Disconnected") tothe >user via a statusBar.
>
>To keep the background thread and user-interfacethreads >seperate, I have a 'Status' property in the background >thread that I would like the UI to occasionally check. >
>To try it out, I created a System.Threading.Timer inthe >UI (Form1) thread and had it run an 'Update' function
>that changes the statusBar.Text property to thecurrent >time. Unfortunately, this seemed to partially freeze
the
>application. I put a MessageBox before the
>statusbar.text update and found that the function
>continues to be called but the thread stops when ithits >the statusBar property.
>
>I tried the same code in a non pocketPC environment
(just
>a regular C# application for winxp) and it works fine. >
>I was wondering what's up with the PocketPC UIthreading >that would make it behave this way.
>
>Any help much appreciated.
>
>
>.
>

.

.

Nov 22 '05 #5

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

Similar topics

1
by: boble | last post by:
Sorry, it's may be off topic ;_((( The following article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnppc2k3/ht ml/winmob03.asp states that a.. Microsoft Windows .NET...
0
by: Earle Oxner | last post by:
We are developing an application on PocketPC2002 platform and we are trying to make webservice calls using HTTPS. HTTP works fine but HTTPS does not work. The same code which doesn't work on...
2
by: Duncan | last post by:
I am using the evaluation version of CE.NET 4.1. I had also installed the release version of the Compact Framework. I uninstalled the CE.NET 4.1, and then realized I needed it again and...
1
by: Asad Khan | last post by:
Hi, I have Visual Studio 2002 Enterprise Architecture Edition. I was wondering if anyone has any information on how I can develop applications for .Net Compact Framework using this IDE. I've heard...
2
by: Hans Kesting | last post by:
Is it possible to mix code meant for the CompactFramework and code meant for the standard framework? We are trying to make PDA and light-weight "laptop" versions of one application. This means a...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
4
by: Joe | last post by:
I'm hosting my web service on a Windows 2003 box which is remotely located. When trying to add a web reference to a C# project I get an error message 'There was an error downloading...
5
by: bob | last post by:
Hi Using 2003 - targeting the compact framework (c#), but would like to do most development using the full.net (manually leaving out stuff not in the compact framework). Q. Trying to find a...
3
by: Greg | last post by:
Hello all, I am looking to download an image from a website from within a compact framework pda app. I have tried everything I could find and thus I turn to you. Any help or suggestions would be...
4
by: jankhana | last post by:
Hi all, I'm having an application in that i use Sql Compact 3.5 with VS2008. I'm running multiple threads in my application which contacts the compact database and accesses the row. It...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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...
0
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 projectplanning, coding, testing,...
0
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
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...

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.