Note that there are some explanatory texts on larger screens.

plurals
  1. POusing C# background worker calling a "toaster" popup not working
    text
    copied!<p>I'm quite new to C#, and I am working on a WPF application that has a background process that long poles a web service. when I get certain codes back from the web service I will kick off methods. I have all working but the one to create a "toaster" popup message. I created a form to act as a toaster popup. My problem is that it is being called from a backroundWorker thread, and it only executes once and it does not slide up the screen. The timer function to raise up the screen does not run. For simplicity I was using code from a previous question answered: </p> <pre><code>public partial class Form1 : Form { private Timer timer; private int startPosX; private int startPosY; public Form1() { InitializeComponent(); // We want our window to be the top most TopMost = true; // Pop doesn't need to be shown in task bar ShowInTaskbar = false; // Create and run timer for animation timer = new Timer(); timer.Interval = 50; timer.Tick += timer_Tick; } protected override void OnLoad(EventArgs e) { // Move window out of screen startPosX = Screen.PrimaryScreen.WorkingArea.Width - Width; startPosY = Screen.PrimaryScreen.WorkingArea.Height; SetDesktopLocation(startPosX, startPosY); base.OnLoad(e); // Begin animation timer.Start(); } void timer_Tick(object sender, EventArgs e) { //Lift window by 5 pixels startPosY -= 5; //If window is fully visible stop the timer if (startPosY &lt; Screen.PrimaryScreen.WorkingArea.Height - Height) timer.Stop(); else SetDesktopLocation(startPosX, startPosY); } } </code></pre> <p>Then in my bgWorker_DoWork method I have: </p> <pre><code> var dict = new JavaScriptSerializer().Deserialize&lt;Dictionary&lt;string, object&gt;&gt;(responseFromServer); int notifyType = (int)dict["notificationType"]; switch (notifyType) { case 6: Debug.WriteLine(responseFromServer); Form1 popup = new Form1(); popup.Show(); break; default: Debug.WriteLine(responseFromServer); break; } </code></pre> <p>Being new to C# I do not know how to keep the timer methods executing till the toaster message is fully displayed.</p> <p>Or is there a better way to implement this toast popup then a form?</p> <p>Help, please?? Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload