CommonUtils.Core.Windows/WindowsUtil.cs

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

//using Microsoft.Win32;
using System;
using System.IO;
using System.Security.Permissions;
using System.Text;
using System.Windows.Forms;
using System.Windows.Threading;

namespace CommonUtils
{
    /// <summary>
    /// 窗口管理
    /// </summary>
    public static class WindowsUtil
    {
        /// <summary>
        /// UI停止刷新
        /// </summary>
        private static object StopFrame(object frame)
        {
            ((DispatcherFrame)frame).Continue = false;
            return null;
        }

        /// <summary>
        /// UI刷新
        /// this.Dispatcher x.Dispatcher Application.Current.Dispatcher
        /// </summary>
        [SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
        public static void RefreshUi(Dispatcher dispatcher)
        {
            DispatcherFrame frame = new DispatcherFrame();
            dispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(StopFrame), frame);
            Dispatcher.PushFrame(frame);
        }

        /// <summary>
        /// 线程调用,自带UI刷新
        /// this.Dispatcher x.Dispatcher Application.Current.Dispatcher
        /// </summary> 
        public static void DispatcherInvoke(Action action, Dispatcher dispatcher)
        {
            dispatcher.Invoke(action);
            RefreshUi(dispatcher);
        }

        /// <summary>
        /// 获取文件夹路径,末尾不带斜杠"\\"
        /// if void main() add[STAThread]
        /// </summary>
        public static string SelectFolder()
        {
            var dialog = new FolderBrowserDialog();
            dialog.SelectedPath = CacheUtil.GetFromFile<string>("FolderBrowserDialog.SelectedPath");
            dialog.ShowDialog();
            CacheUtil.SaveWithFile("FolderBrowserDialog.SelectedPath", dialog.SelectedPath);
            return dialog.SelectedPath;
        }

        /// <summary>
后面还有 100 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。