私は C# にまったく慣れていません。Web サービスを長くポールするバックグラウンド プロセスを持つ WPF アプリケーションに取り組んでいます。Web サービスから特定のコードを取得したら、メソッドを開始します。「トースター」ポップアップメッセージを作成するもの以外はすべて機能しています。トースターのポップアップとして機能するフォームを作成しました。私の問題は、backroundWorker スレッドから呼び出されており、一度しか実行されず、画面を上にスライドしないことです。画面アップのタイマー機能が動作しません。簡単にするために、以前の質問に回答したコードを使用していました。
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 < Screen.PrimaryScreen.WorkingArea.Height - Height)
timer.Stop();
else
SetDesktopLocation(startPosX, startPosY);
}
}
次に、私の bgWorker_DoWork メソッドには次のものがあります。
var dict = new JavaScriptSerializer().Deserialize<Dictionary<string,
object>>(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;
}
C# が初めてなので、トースター メッセージが完全に表示されるまでタイマー メソッドを実行し続ける方法がわかりません。
または、このトーストポップアップをフォームよりも実装するためのより良い方法はありますか?
助けてください??ありがとうございました。