0

I created application in C# windows forms and there is notificationForm which shows after time, but it's completely empty without my label and picture. If I show this notificationForm manually everything works perfect.

private static void OnTimedEventZak(Object source, System.Timers.ElapsedEventArgs e)
{
    Mydb context = new Mydb ();
    var getReservation = context.column.Where(i => i.column_id== idForMethods).FirstOrDefault();
    if (getReservation.Status_id == 2)
    {
        Notification p = new Notification(getReservation.column_id,false);
        p.Show();
    }        
}

It renders like this:

Image

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
Kostar
  • 1
  • 1
  • Every time you open your Notification form you are creating a new instance of the form and loosing the old values. What does false parameter indicate? Are you keeping the form open so you are creating multiple instances of the form? See my two form project : https://stackoverflow.com/questions/34975508/reach-control-from-another-page-asp-net – jdweng Dec 31 '20 at 11:18
  • false parameter is my flag for this Notification, im new at creating windowsForm so im still learing about openning and closing forms, thanks for advice i will check it @jdweng – Kostar Dec 31 '20 at 11:22

1 Answers1

0

You're using System.Timers.Timer, so you're showing the form on a thread that doesn't pump messages (i.e. not the "UI thread").

Use System.Windows.Forms.Timer.

Also, dispose your context, and consider that FirstOrDefault() can return null.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272