Jump to content
  • Advertisement
Sign in to follow this  
hammet1982

Problem with C# Forms and Invalidate

This topic is 3854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am writing a program that reads data on a card automatically and then displays it on a C# form. I'm using a label to display the information. I am using a thread to pull the information off the card constantly, but my problem is that even though i am calling Invalidate and Update the text won't update unless I click on the screen or move the mouse. Please help. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Sorry about the delay in posting. I had a bit of an emergency. Hopefully someone can help me with this still. Here is my code. Thanks.

pCardScanThread.Suspend();

while (!pCardScanThread.pThreadStopped)
System.Threading.Thread.Sleep(10);

currentPlayer.serviceAmt = pCardScanThread.Balance;
currentPlayer.gameRoom = pCardScanThread.GameRoom;
currentPlayer.cardNum = pCardScanThread.CardNum;

CashRegCardNumTextLabel.Text = currentPlayer.cardNum.ToString();
decimal dispBalance = currentPlayer.serviceAmt / CONVERSION_AMOUNT;
CashRegCardBalanceTxtLabel.Text = dispBalance.ToString("N2");

pCardScanThread.Resume();

CashRegCardBalanceLabel.Invalidate();
CashRegCardBalanceLabel.Update();

CashierRegisterPanel.Invalidate();
CashierRegisterPanel.Update();

Share this post


Link to post
Share on other sites
This is being called inside of Wndproc also. I had to override it. So I call that, and then call the base Wndproc. When I step through the code in debug as soon as it hits Update it redraws the screen with the new values, but if I let it just run through automatically it will not redraw.

Share this post


Link to post
Share on other sites
I think I figured out the problem. But now the solution is perplexing. I've figured out that Wndproc doesn't get called when the form is idle. So its not getting called until there is a button press or a mouse movement or mouse press. So if anyone can help me come up with a solution so that the Wndproc will be called constantly that would be great. Thanks.

Share this post


Link to post
Share on other sites
Quote:
Original post by benryves
I would not put that code inside WndProc; take a look at the Application.Idle event.


Wouldn't this just flip the situation and only call during the application idle event?

Share this post


Link to post
Share on other sites
I put in that Application_Idle and its working nicely for the most part. I have multiple panels that I switch between in this program, but I only pull the value in a certain screen. SO when I switch screens and return it no longer goes. I'm going to check it out. Thanks again for your help.

Share this post


Link to post
Share on other sites
Application.Idle only fires once, when the application becomes idle. Keep that in mind. Likely you're seeing it fired repeatedly because you are also forcing repaints with Invalidate().

A common method is to p/invoke PeekMessage and use it to run a "while app still idle" (e.g., "while no messages in the queue") loop in the Idle handler.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
Application.Idle only fires once, when the application becomes idle. Keep that in mind. Likely you're seeing it fired repeatedly because you are also forcing repaints with Invalidate().

A common method is to p/invoke PeekMessage and use it to run a "while app still idle" (e.g., "while no messages in the queue") loop in the Idle handler.


I'm sort of new to C#. Can you point me to a good tutorial on how to use this P/Invoke in order to get this to work. Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!