- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有 WinForms 应用程序,我在其中使用以下帖子中的代码来检查我的应用程序的非事件状态(请参阅帖子中已接受的答案)。 InActivity In WinForms .一旦应用程序达到不活动状态,它就会停止不活动监视器。但是我想在用户登录后重新开始计时。
所以当用户登录时我有一个通知机制,我再次调用启动计时器方法。我收到 Started Monitor 消息,但该应用程序从不跟踪不活动状态,而且我根本没有收到 Timer 报告应用程序处于 InACTIVE 消息。请帮忙。
public static System.Windows.Forms.Timer IdleTimer =null;
static int MilliSeconds = 60000;
static void Main(string[] args)
{
f = new GeneStudyForm(true, arguments.SystemTimeOutFolder, arguments.SystemTimeOutFile, StartInActivityMonitor);
int x = StartInActivityMonitor();
}
public static void StartInActivityMonitor()
{
IdleTimer = new Timer();
LeaveIdleMessageFilter limf = new LeaveIdleMessageFilter();
Application.AddMessageFilter(limf);
IdleTimer.Interval = MilliSeconds; //One minute; change as needed
Application.Idle += new EventHandler(Application_Idle);
if (IdleTimer != null)
{
MessageBox.Show(IdleTimer.Interval.ToString());
}
IdleTimer.Tick += TimeDone;
IdleTimer.Tag = InActivityTimer.Started;
MessageBox.Show("starting");
IdleTimer.Start();
}
static private void Application_Idle(object sender, EventArgs e)
{
if (!IdleTimer.Enabled) // not yet idling?
IdleTimer.Start();
}
static private void TimeDone(object sender, EventArgs e)
{
try
{
MessageBox.Show("Stopped");
IdleTimer.Stop(); // not really necessary
f.MonitorDirectory();
f.UpdateInActivityStatus();
IdleTimer.Tick -= TimeDone;
Application.Idle -= new EventHandler(Application_Idle);
}
catch(Exception ex)
{
MessageBox.Show(ex.InnerException + ex.Data.ToString());
}
}
这是我的 GeneStudyForm
public partial class GeneStudyForm
{
GeneStudySystemTimeOutIO GeneStudyIO;
Func<int> StartTimer;
//Passing the StartInActivityMonitor Method as Func Delegate
public GeneStudyForm(bool isStandalone, string TimeOutFolder, string TimeOutFile, System.Func<int> MyMethod)
{
GeneStudyIO = GeneStudySystemTimeOutIO.GetInstance(TimeOutFolder, TimeOutFile);
UpdateActivityStatus(AppName.GeneStudyStatus, ActivityStatus.Active);
this.StartTimer = MyMethod;
}
public void UpdateActivityStatus(AppName name, ActivityStatus status)
{
if (GeneStudyIO != null)
{
GeneStudyIO.WriteToFile(name, status);
}
}
public void MonitorDirectory()
{
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(GeneStudyIO.GetDriectory());
fileSystemWatcher.NotifyFilter = NotifyFilters.LastWrite;
fileSystemWatcher.Filter = "*.json";
fileSystemWatcher.Changed += FileSystemWatcher_Changed;
fileSystemWatcher.EnableRaisingEvents = true;
}
public void UnRegister(FileSystemWatcher fileSystemWatcher)
{
fileSystemWatcher.Changed -= FileSystemWatcher_Changed;
}
// I am writing the inactive status to a file. So this event will fill
private void FileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
{
try
{
var root = GeneStudyIO.GetDesrializedJson();
if (root != null && root.AllApplications != null)
{
var item = root.AllApplications.Any(x => x.Status == ActivityStatus.Active.ToString());
if (!item)
{
if (InActivecount == 0)
{
GeneStudyAndApplicationCommon.TimeStatus = InActivityTimer.Ended;
MessageBox.Show("I am hiding");
this.Hide();
InActivecount++;
}
}
else
{
if (GeneStudyAndApplicationCommon.TimeStatus == InActivityTimer.Ended)
{
MessageBox.Show("I am showing");
this.Show();
UnRegister(sender as FileSystemWatcher);
UpdateActivityStatus(AppName.GeneStudyStatus, ActivityStatus.Active);
MessageBox.Show("Updated Status");
if (StartTimer != null)
{
MessageBox.Show("Starting Timer again");
if (StartTimer() == -1)
{
MessageBox.Show("Couldn't start timer");
}
}
}
}
}
}
catch (Exception ex)
{
SystemDebugLogLogger.LogException(ex);
}
}
}
最佳答案
这个解决方案与我发布的完全不同。但我可以用这个解决我的问题。但如果它对某人有帮助,我想发布它。这是我关注的帖子 Last User Input
我创建了一个名为 IdleCheck 的类,我在其中按如下方式获取 LastUserInput
public static class IdleCheck
{
[StructLayout(LayoutKind.Sequential)]
private struct LASTINPUTINFO
{
[MarshalAs(UnmanagedType.U4)]
public int cbSize;
[MarshalAs(UnmanagedType.U4)]
public int dwTime;
}
[DllImport("user32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO x);
public static int GetLastInputTime()
{
var inf = new LASTINPUTINFO();
inf.cbSize = Marshal.SizeOf(inf);
inf.dwTime = 0;
return (GetLastInputInfo(ref inf)) ? Environment.TickCount - inf.dwTime : 0;
}
}
接下来在实际的表单中,这是我的代码。我正在使用一个简单的是否消息框来查看计时器是否可以停止并在需要时再次调用。您可以应用自己的锁定机制。我希望应用程序在 InActive 状态持续 20 秒后超时。根据需要更改它。
public partial class Form1 : Form
{
Timer timer;
const int TIMEOUT_DONE = 20000;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Reset();
}
void timer_Tick(object sender, EventArgs e)
{
//var ms = TIMEOUT_DONE - IdleCheck.GetLastInputTime();
if (IdleCheck.GetLastInputTime() > TIMEOUT_DONE)
{
DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
Stop();
Reset();
}
}
}
public void Reset()
{
timer = new Timer();
timer.Interval = 10000;
timer.Tick += timer_Tick;
timer.Start();
}
public void Stop()
{
timer.Tick -= timer_Tick;
timer.Stop();
}
}
关于c# - 计时器停止后重新启动 InActivity Monitor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50751919/
我基于Symfony2 security documentation设置了应用程序的身份验证系统。 我的每个用户都有一个active标志。我不希望active = false的用户能够登录。 我真的不
我正在以只读方式使用旧式数据库。我有一个用户域,其中包括用户是否处于 Activity 状态的标志。当调用诸如findAll之类的搜索方法时,有没有办法总是忽略不 Activity 的用户而不将其从数
我想随时捕捉关键事件,即使我的应用程序不在焦点上。例如,当焦点位于其他应用程序时,我的应用程序应该检测 Ctrl+SPACE 组合键,并应做出相应的响应。谢谢 最佳答案 这是特定于操作系统的,不在 J
我在哪里 选择曲棍球运动员后,将其默认的 is-inactive 类别切换为 is-active 来表示。我还添加了 full 类,以防止选择 picked.is-inactive 类的玩家。 问题
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit th
我正在创建一个网站(显然是初学者),出于某种原因,在我的一个页面上,页 footer 分比预期的要长得多。它很奇怪,因为在其他页面上,它看起来很好。我在新页面上使用了完全相同的代码,但页脚完全不正常。
我有 WinForms 应用程序,我在其中使用以下帖子中的代码来检查我的应用程序的非事件状态(请参阅帖子中已接受的答案)。 InActivity In WinForms .一旦应用程序达到不活动状态,
Korbel 先生非常感谢您 我在 JPanel 上有一个鼠标监听器,它工作正常。我正在尝试向 JLabel 添加一些翻转支持,但是当我将鼠标监听器添加到 JLabel 时,JPanel 的鼠标监听器
我有 2 个表: 用户 编号 |姓名 |邮件 |通过 |盐 条目 编号 | uid |标题 |文字 |时间戳 现在我想删除所有带有 uid 的 entries 行,它在 user 表中不存在(删除用户
问题 每个位置的最大玩家人数是: 4 个守门员中有 2 个 15 名防守队员中有 6 名 31 名前锋中有 12 名 我已经到了这样的地步,我将点击一个曲棍球运动员,该名字将被添加到表单的输入字段中,
我有一个餐厅控制面板,它会在下订单时播放提示音。问题是,当控制面板选项卡不是 Chrome 中的事件选项卡时(对于 Firefox 也是如此),警报声音不会播放。单击选项卡后,它会播放声音。 我看到一
目标 在每个类别中选择了最大数量的球员(两名守门员、六名防守队员、十二名前锋)后,剩余球员 picked同类is-inactive应该设置为 cursor:default 问题的澄清 所有玩家都有类
错误 我的场景 首先我知道这个错误消息是 CSRF/ session 错误消息,没关系;事实上它的行为符合预期。由于我的应用程序的特定原因,我这样做是为了访问帐户,我发送一个发布请求并根据该响应数据构
我使用 Firebase 只是为了分析。我昨天成功实现了 Firebase。事实上,我没有收到任何运行时错误,但我在 Logcat 中注意到了。 2-3 秒后,Logcat 中会显示此消息。 V/FA
我对 iPhone 开发还很陌生。我有我的“根” View ,它正在实现 - (void)accelerometer:(UIAccelerometer *)accelerometer didAccel
我有一个相当长的 div 列表,我试图将其用作可放置的 - 但我想隐藏所有不接受当前可拖动元素的可放置。 我在 http://jsfiddle.net/N3uh3/ 上举了一个例子 基本上,如果我拖动
我的屏幕类似于: 我想删除 tableView 中最后一个“事件”单元格下方的分隔符(在本例中为“Kompozytorzy”下方的所有内容)。如何删除此分隔符? 我尝试在 cellForRow:AtI
这个问题在这里已经有了答案: V/FA: Processing queued up service tasks: 1 followed by V/FA: Inactivity, disconnecti
我有一项服务将永远运行,无论是否有客户端访问该服务,但在很长一段时间没有客户端事件之后,才能与客户端连接。 这是因为,例如,在假期过后,我希望能够连接到服务,而无需手动重新启动服务。 目前,如果10分
我在 Urban Airship 上收到以下错误消息。 Apple Push service rejected device token 38A69702F555A3B17F73FB4DB8
我是一名优秀的程序员,十分优秀!