首页 > 解决方案 > iMobileDevice-Net event trigger when photo added or deleted

问题描述

Is there any way in 'iMobileDevice-Net' library to trigger an event when photos on the connected device change? ex. when you delete a photo from device or take a new photo while the device is connected. So far, I have to check the Modification Time ("st_mtime") property of the photo database on a regular basis using timer trigger to check for the changes and I think this way is not the best way to do this specially if I set the interval time low.

private void Timer1_Tick(object sender, EventArgs e)
{
    string path = @"/PhotoData/Photos.sqlite-wal";
    ReadOnlyCollection<string> infoList;
    var returnCode = afcApi.afc_get_file_info(clientHandle, path, out infoList);
    long filemtime = Convert.ToInt64(infoList[infoList.IndexOf("st_mtime") + 1]) / 1000000000;
    DateTime modificationTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
    modificationTime = modificationTime.AddSeconds(filemtime).ToLocalTime();
    if (modificationTime > lastModificationTime)
    {
        lastModificationTime = modificationTime;
        DoTrigger();
    }
}

标签: c#eventsfilesystemwatcherlibimobiledevice

解决方案


推荐阅读