我有一个 flutter 桌面应用程序,想防止它的多个实例同时运行。我尝试为此使用 Mutex,但代码不起作用。任何人都可以为我更正吗?或者告诉我其他方法吗? 这是我的代码打击:
import 'package:mutex/mutex.dart';
import 'dart:io';
void main() async {
final mutex = Mutex();
if (await mutex.acquire() == null) {
runApp(MyApp());
mutex.release();
} else {
// The mutex is already held by another instance of the app.
// You can choose to show an error message or just exit silently.
exit(0);
}
}