Timer Help Needed Win{C#]

M

MikeY

It seems that when I call the Timer.Stop(). That my main form does not
appear correctly. All Added Controls, label box's, buttons are missing.
Hopefully someone will have a simple answer: My code is below, and thank you
all in advance.

private void Pad_Exit_Timer()

{

//*Every 1000 is 1Second

Exit_Timer = new Timer();

Exit_Timer.Tick += new EventHandler(Exit);

Exit_Timer.Interval = 5000;

Exit_Timer.Enabled = true;

Exit_Timer.Start();

}

//

private void Exit(Object source, EventArgs e)

{

//Dispose Of Added Control

Pad_ExitScreen.Dispose();

//This Is A Test. Main Form Is Fine At This Point

MessageBox.Show("HELLO");

//

Exit_Timer.Stop();

//Main Form Doesn't fully appear after this All Buttons, controls are
missing & can see screen desktop behind

}
 
P

Peter Duniho

MikeY said:
It seems that when I call the Timer.Stop(). That my main form does not
appear correctly. All Added Controls, label box's, buttons are missing.
Hopefully someone will have a simple answer: My code is below, and thank you
all in advance.

You didn't post enough code for anyone to reproduce the problem. You
should create a concise-but-complete sample of code that reliably
reproduces the problem. Concise means it doesn't have anything that
isn't directly related to reproducing the problem and complete means
that someone can take the code and compile it without having to add
anything else.

By the way, it's redundant to set Timer.Enabled and to call
Timer.Start(). They do the same thing.

Pete
 
M

MikeY

Hi Peter,

I was just hoping for a quick fix to why my application appears to freezing,
with my shortened code, because of all the custom buttons involved. I'll see
what I can do about it.

Thanks

MikeY
 
P

Peter Duniho

MikeY said:
I was just hoping for a quick fix to why my application appears to freezing,
with my shortened code, because of all the custom buttons involved. I'll see
what I can do about it.

I do understand the temptation to just "hope for a quick fix". Been
there, done that. Unfortunately, the code you posted doesn't provide
any path to a quick fix. Whatever is going wrong, unfortunately it's
not in the code you posted.

Pete
 
M

MikeY

You are definitely correct Peter and unfortunately that's why I haven't
posted back ......yet. It does appear that the code is indeed fine. And now
I'm not sure what to post.

The problem is this if I can converse it properly. & I understand if its
hard to follow, and I will try to figure out the problem. But here goes....

I have a Floorplan with tables. Once a table is selected, the user goes to
the Order Screen.

In the Order Screen -> Upon the user selecting a button called "ORDER", the
Order Screen gets Dispose().
The Floor Plan will then re-appears & also does an Exit_Pad (Control) that
allows the user to continue, sign-out, or goback to the table. This all
works great, but the problem lies in that there is also a timer involved In
The Exit_Pad (Control) so that if the user doesn't sign-out, the system
after a certian amount of time 5 seconds, will automatically sign out the
user. When any of the above happens, the Floor Plan Screen should be
displayed correctly and the user can continue, but the system freezes.

Now when I skip the //floor plan being called again after the "ORDER" button
has been clicked, then the system works fine. & this is how I found out that
it was infact not my Exit_Pad (Control)

Just in case you would like to see a bit of the code from the Pad Control
and the main calling, it is as follows: and once again if I leave out the
call to Display the Floor Plan Screen Under "OrderZone_Return" everything
works fine. But it might have something to do with the floor plan being
called again from here.

PAD_EXIT_SCREEN

//Delegate To Pass Items Back To Management Zone

public delegate void Pad_Exit_Screen_ItemPass(string Item_Name);



public class Pad_Exit_Screen : System.Windows.Forms.UserControl

{

public event Pad_Exit_Screen_ItemPass Item_Pass;

//------------------------------------------------------------

//

//------------------------------------------------------------

public Pad_Exit_Screen()

{

InitializeComponent();



//Set Date/Time

Internal_Timer = new Timer();

Internal_Timer.Tick += new EventHandler(Display_Alert);

Internal_Timer.Interval = 500;

Internal_Timer.Enabled = true;



//Exit Timer

//*Every 1000 is 1Second

Exit_Timer = new Timer();

Exit_Timer.Tick += new EventHandler(Exit);

Exit_Timer.Interval = 5000;

Exit_Timer.Enabled = true;

}

....

//------------------------------------------------------------

//

//------------------------------------------------------------

//Get User Response From Button Click

private void On_Click(object sender, System.EventArgs e)

{

Button Button_Item = (Button)sender;



if(Button_Item.Text == "EXIT")

{

Item_PassBack(Button_Item.Text);

}

else if(Button_Item.Text == "CONTINUE")

{

Item_PassBack(Button_Item.Text);

}

//Go Back To The Table

else if(Button_Item.Text == "RETURN TO TABLE")

{

Item_PassBack(Button_Item.Text);

}

}

//------------------------------------------------------------

//

//------------------------------------------------------------

//If User Inputs A Reminder ie: Birthday/Pre-Theatre

protected void Display_Alert(Object source, EventArgs e)

{

if(Alert_Click == true)

{

this.BackColor = System.Drawing.Color.Red;

Alert_Click = false;

}

else

{

this.BackColor = System.Drawing.Color.Gold;

Alert_Click = true;

}

}

//------------------------------------------------------------

//

//------------------------------------------------------------

//

private void Exit(object sender, EventArgs e)

{

Item_PassBack("Exit");

}

//------------------------------------------------------------

//

//------------------------------------------------------------

//Pass Back Selected Button Name

protected virtual void Item_PassBack(string Item_Name)

{

Internal_Timer.Stop();

Exit_Timer.Stop();

//

this.Dispose();

//

Item_Pass(Item_Name);

}



MAIN



//------------------------------------------------------------

//ORDER ZONE

//------------------------------------------------------------

//Display Order_Zone

private void Display_Order_Zone()

{

//Call Order Screen

OrderZone = new Order_Zone();

//Pass Order Screen Required Information

OrderZone.GETSET_CURRENT_USER = GETSET_CURRENT_EMP_FNAME;

OrderZone.GETSET_CURRENT_TABLENUMBER = GETSET_CURRENT_TABLE_NUMBER;

OrderZone.GETSET_CURRENT_EMP_PASSWORD = GETSET_CURRENT_EMP_PASSWORD;

OrderZone.GETSET_CURRENT_EMP_TITLE = GETSET_CURRENT_EMP_TITLE;

OrderZone.GETSET_CURRENT_EMP_ACCESSLEVEL
=gETSET_CURRENT_EMP_ACCESSLEVEL;



if(GETSET_AL_TABLEITEMS != null)

{

OrderZone.GETSET_AL_TABLEITEMS = this.GETSET_AL_TABLEITEMS;

}



OrderZone.Show();

OrderZone.Item_Pass += new Order_Zone_ItemPass(OrderZone_Return);

OrderZone.BringToFront();

}

//Display FloorPlan For The Background & Pad Exit For Choice

private void OrderZone_Return(string Item_Info)

{

if(Item_Info == "FloorPlan")

{

Display_FloorPlan();

Display_Pad_ExitScreen();

}

}

//------------------------------------------------------------

//EXIT SCREEN

//------------------------------------------------------------

//

private void Display_Pad_ExitScreen()

{

Pad_ExitScreen = new Pad_Exit_Screen();

Pad_ExitScreen.Location = new System.Drawing.Point(280, 30);

Pad_ExitScreen.Show();

this.Controls.Add(Pad_ExitScreen);

Pad_ExitScreen.BringToFront();

Pad_ExitScreen.Item_Pass += new
Pad_Exit_Screen_ItemPass(Pad_ExitScreen_Return);

}

//

private void Pad_ExitScreen_Return(string Item_Info)

{

if(Item_Info == "EXIT")

{

..Do Something

}

else if(Item_Info == "CONTINUE")

{

..Do Something

}

//Go Back To Previously Selected Table

else if(Item_Info == "RETURN TO TABLE")

{

..Do Something

}

}

//------------------------------------------------------------

//FLOOR PLAN

//------------------------------------------------------------

//Display FloorPlan

private void Display_FloorPlan()

{

//Display FloorPlan

Floor_Plan = new FloorPlan();

Floor_Plan.Location = new System.Drawing.Point(5, 5);

Floor_Plan.GETSET_CURRENT_USER_ID = GETSET_CURRENT_EMP_PASSWORD;

Floor_Plan.GETSET_CURRENT_USER = GETSET_CURRENT_EMP_FNAME;

Floor_Plan.GETSET_CURRENT_TABLENUMBER = Current_TableNumber;

Floor_Plan.GETSET_CURRENT_ACCESSLEVEL =
GETSET_CURRENT_EMP_ACCESSLEVEL;

Floor_Plan.Show();

this.Controls.Add(Floor_Plan);

Floor_Plan.BringToFront();

//

Floor_Plan.Item_Pass += new FloorPlan_ItemPass(FloorPlan_Return);

Floor_Plan.Item_PassTable += new
FloorPlan_ItemPassTable(FloorPlan_TableReturn);

Floor_Plan.Item_PassRedirection += new
FloorPlan_Item_PassRedirection(FloorPlan_RedirectionReturn);

}
 
P

Peter Duniho

MikeY said:
[...] This all
works great, but the problem lies in that there is also a timer involved In
The Exit_Pad (Control) so that if the user doesn't sign-out, the system
after a certian amount of time 5 seconds, will automatically sign out the
user. When any of the above happens, the Floor Plan Screen should be
displayed correctly and the user can continue, but the system freezes.

I didn't look very closely at the code you posted. Sorry, but it's just
got too much unrelated stuff for me to easily focus in on what might
actually be the issue.

That said, calling Dispose() isn't necessarily the right way to get rid
of the "Order Screen". There are other issues with the code, but
basically you can't just dispose a control on a form. You have to
remove it from the form first (Controls.Remove()).

It sounds as though you might not have removed the control, so when you
dispose it, the form still thinks it exists, but of course since it's
disposed it's not actually around to draw itself, so you get the "see
through" effect.

Pete
 
M

MikeY

Hi Peter.

I think your correct and that in fact might be the problem of the Control
just not being removed.
Going to run with that Idea, and if I still run into problems, I'll start a
new thread.

Thank you once again

MikeY

Peter Duniho said:
MikeY said:
[...] This all
works great, but the problem lies in that there is also a timer involved
In The Exit_Pad (Control) so that if the user doesn't sign-out, the
system after a certian amount of time 5 seconds, will automatically sign
out the user. When any of the above happens, the Floor Plan Screen should
be displayed correctly and the user can continue, but the system freezes.

I didn't look very closely at the code you posted. Sorry, but it's just
got too much unrelated stuff for me to easily focus in on what might
actually be the issue.

That said, calling Dispose() isn't necessarily the right way to get rid of
the "Order Screen". There are other issues with the code, but basically
you can't just dispose a control on a form. You have to remove it from
the form first (Controls.Remove()).

It sounds as though you might not have removed the control, so when you
dispose it, the form still thinks it exists, but of course since it's
disposed it's not actually around to draw itself, so you get the "see
through" effect.

Pete
 
M

MikeY

BAH. Peter its called being an idiot. I was calling the Floor Plan to create
the floor plan again when I didn't need to, DOH.

Thank you once again.

MikeY
 
P

Phil H

Hi Mike,
I am no expert in C#, just starting to learn. But I share something with you
that might help.
I have VB6 program (Restraunt POS app) and the owner said it freeze. It took
me a long time to figure out. The program has a timer that pops up a login
screen after certain time lapse. THe problem is in certain situation I have
msgbox that tell the user something. If I have a msgbox and the user does
not close it and the login screen pops up. The program freeze because the
msgbox is in the background (or sometime invisible). The msgbox is modal, so
the program cannot proceed. What really complicates matter is, it does not
happen in IDE so I could not duplicate the problem for a long long time. So
I suggest you to run the exe instead to see if you can pinpoint how and when
the freeze happens.
 
M

MikeY

Thank you Phil,

LOL Funny thing is, that is exactly what I'm building. A retaurant POS, one
that work with out all these problems that arise from the stuff that's on
the market now. Plus having a lot of experience in that particular business,
I'm putting in a bunch of not so much as bell and whistles, but things
programers in the past have missed, being not from that background or
understanding.

Thanks gain Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top