LoginSignup
10
13

More than 1 year has passed since last update.

WPF+Prismで二重起動防止する方法

Last updated at Posted at 2021-07-16

背景

しばらくWPFを勉強していて、「やっぱりフレームワークを利用するのがいいんだろな」と思い至り、とりあえずPrismから触ってみることにした。
仕事で触ってるWPFアプリでは二重起動防止の仕組みが用意されていることは知っていたけど、そもそも二重起動防止の機能を実装した経験がないので、せっかくなのでWPF+Prismでの実装方法を確認してみようと思った。

環境

OS: Windows 10 Pro
IDE: Visual Studio 2019 Community Version 16.10.3
Target Framework: .NET 5.0
使用したFramework: Prism

手順

1. App.xaml と App.xaml.cs を開く
2021-07-16_17h56_47.png

2. App.xaml で Startupイベント と Exitイベント を定義
2021-07-16_17h59_39.png

3. App.xaml.cs で 処理内容を記述
2021-07-16_18h07_47.png

動作確認

▼1個目起動
2021-07-16_18h12_49.png

▼2個目起動時
2021-07-16_18h13_03.png

感想

とりあえず参考の通りに記述して書き方は分かったけど、これって別にWPFとかPrism関係なくて、C#の言語仕様で用意された機能だってことに気づいた。笑
今回の記述箇所(StartupとかExit)はPrism独特のものっぽいから、Prism以外で実装するときはそれぞれのエントリーポイントを確認する必要ありかな。

参考

10
13
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
13