In the process of developing software, SQLite is usually chosen as the local database, because its configuration is relatively simple and no additional database services are required. SQLite can well support some basic features of relational database, such as standard SQL syntax, things, data tables and indexes, etc., and it takes less resources, and can also be easily used on mobile devices.

In addition, some features of Entity Framework (such as fluent API, migration, etc.) can make it very convenient for us to operate SQLite, and its development team is still continuing the iteration of the project, which can be the reason why we use EF core.

A data model changes during development and gets out of sync with the database. You can drop the database and let EF create a new one that matches the model, but this procedure results in the loss of data. The migrations feature in EF Core provides a way to incrementally update the database schema to keep it in sync with the application's data model while preserving existing data in the database.

Read the code directly and understand everything...

public class HookHandler
{
    public void InitializeHook(Visual visual)
    {
        HwndSource hwndSource = PresentationSource.FromVisual(visual) as HwndSource;//窗口过程

        if (hwndSource != null)
        {
            hwndSource.AddHook(new HwndSourceHook(WndProc));//挂钩
        }
    }

    public const int WM_DEVICECHANGE = 0x219;//U盘插入后,OS的底层会自动检测到,然后向应用程序发送“硬件设备状态改变“的消息
    public const int DBT_DEVICEARRIVAL = 0x8000;  //就是用来表示U盘可用的。一个设备或媒体已被插入一块,现在可用。
    public const int DBT_CONFIGCHANGECANCELED = 0x0019;  //要求更改当前的配置(或取消停靠码头)已被取消。
    public const int DBT_CONFIGCHANGED = 0x0018;  //当前的配置发生了变化,由于码头或取消固定。
    public const int DBT_CUSTOMEVENT = 0x8006; //自定义的事件发生。 的Windows NT 4.0和Windows 95:此值不支持。
    public const int DBT_DEVICEQUERYREMOVE = 0x8001;  //审批要求删除一个设备或媒体作品。任何应用程序也不能否认这一要求,并取消删除。
    public const int DBT_DEVICEQUERYREMOVEFAILED = 0x8002;  //请求删除一个设备或媒体片已被取消。
    public const int DBT_DEVICEREMOVECOMPLETE = 0x8004;  //一个设备或媒体片已被删除。
    public const int DBT_DEVICEREMOVEPENDING = 0x8003;  //一个设备或媒体一块即将被删除。不能否认的。
    public const int DBT_DEVICETYPESPECIFIC = 0x8005;  //一个设备特定事件发生。
    public const int DBT_DEVNODES_CHANGED = 0x0007;  //一种设备已被添加到或从系统中删除。
    public const int DBT_QUERYCHANGECONFIG = 0x0017;  //许可是要求改变目前的配置(码头或取消固定)。
    public const int DBT_USERDEFINED = 0xFFFF;  //此消息的含义是用户定义的
    public const uint GENERIC_READ = 0x80000000;
    public const int GENERIC_WRITE = 0x40000000;
    public const int FILE_SHARE_READ = 0x1;
    public const int FILE_SHARE_WRITE = 0x2;
    public const int IOCTL_STORAGE_EJECT_MEDIA = 0x2d4808;

    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        if (msg == WM_DEVICECHANGE)
        {
            switch (wParam.ToInt32())
            {
                case DBT_DEVICEARRIVAL:
                    HandleUSBHookMonition();
                    break;
                case DBT_DEVICEREMOVECOMPLETE:
                    HandleUSBHookMonition();
                    break;
                default:
                    break;
            }
        }
        return IntPtr.Zero;
    }

    private void HandleUSBHookMonition()
    {
    
    }
}

How to use

private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
    this.Loaded -= MainWindow_Loaded;

    InitializeHook(this);
}

Because when using the shell to take thumbnails, the read images of damaged files have black edges, the following methods are born, but the efficiency is 3-4 times lower than that of using the shell (the time-consuming process is mainly in the process of turning the black background into transparent).

HTML canvas is widely used in games and complex image visualization. However, as websites and applications push canvas rendering to the limit, performance becomes a problem.

Here are some suggestions to improve performance:


Pre render similar shapes or duplicate objects on off screen canvas

When we find that there are many complex drawing operations in every frame, please consider creating an off screen canvas, drawing the image on this canvas once (or every time the image changes), and then drawing the canvas beyond the line of sight on each frame.

myEntity.offscreenCanvas = document.createElement("canvas");
myEntity.offscreenCanvas.width = myEntity.width;
myEntity.offscreenCanvas.height = myEntity.height;
myEntity.offscreenContext = myEntity.offscreenCanvas.getContext("2d");

myEntity.render(myEntity.offscreenContext);

Popular Posts

Collections