Проверьте, неактивно ли приложение какое-то время период, и заблокируйте его

NSDictionary и NSMutableDictionary?

И вот простой пример:

NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
[dictionary setObject:anObj forKey:@"foo"];
[dictionary objectForKey:@"foo"];
[dictionary removeObjectForKey:@"foo"];
[dictionary release];

7
задан Sauron 9 October 2009 в 06:42
поделиться

2 ответа

You can use these functions

see this code, you must add a timer to your form, and set this.timer1.Enabled = true;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication9
{
  internal struct LASTINPUTINFO
  {
    public uint cbSize;    
    public uint dwTime;
  }

  public partial class Form1 : Form
  {

    [DllImport("User32.dll")]
    public static extern bool LockWorkStation();
    [DllImport("User32.dll")]
    private static extern bool GetLastInputInfo(ref LASTINPUTINFO Dummy);
    [DllImport("Kernel32.dll")]
    private static extern uint GetLastError();

public static uint GetIdleTime()
{
  LASTINPUTINFO LastUserAction = new LASTINPUTINFO();
  LastUserAction.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(LastUserAction);
  GetLastInputInfo(ref LastUserAction);
  return ((uint)Environment.TickCount - LastUserAction.dwTime);
}

public static long GetTickCount()
{
  return Environment.TickCount;
}

public static long GetLastInputTime()
{
  LASTINPUTINFO LastUserAction = new LASTINPUTINFO();
  LastUserAction.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(LastUserAction);
  if (!GetLastInputInfo(ref LastUserAction))
  {
    throw new Exception(GetLastError().ToString());
  }

  return LastUserAction.dwTime;
}

    public Form1()
    {
      InitializeComponent();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
      if (GetIdleTime() > 10000)  //10 secs, Time to wait before locking
        LockWorkStation();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      timer1.Start();
    }
  }
}
15
ответ дан 6 December 2019 в 12:52
поделиться

Set a timeout on load, and every time an "active" action happens (you'll need to hook up to them), reset the timer back to the start.

0
ответ дан 6 December 2019 в 12:52
поделиться
Другие вопросы по тегам:

Похожие вопросы: