简体   繁体   English

GetManifestResourceStream-如何帮助缓存?

[英]GetManifestResourceStream - how can it help caching?

i searched for embedding custom drag and drop cursor in my wpf app. 我搜索了在wpf应用程序中嵌入自定义拖放光标的信息。 i ended up with an article which i have no idea of ONE LINE in the code suggested in (it is highlighted with the comments): 我最后写了一篇文章 ,在其中建议的代码中我不知道任何一行(用注释突出显示):

   private void textBlock2_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        TextBlock btn = (TextBlock)sender;

        GiveFeedbackEventHandler handler = new GiveFeedbackEventHandler(DragSource_GiveFeedback);
        btn.GiveFeedback += handler;


        DataObject dataObj = new DataObject(btn.Text);
        DragDrop.DoDragDrop(btn, dataObj, DragDropEffects.Move);
        btn.GiveFeedback -= handler;

    }

    void DragSource_GiveFeedback(object sender, GiveFeedbackEventArgs e)
    {
        try
        {
            if (_allOpsCursor == null)
            {

                ////////////////////////////////////////THE UNKOWN ONE LINE STARTS HERE
                using (Stream cursorStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("SimplestDragDrop.DDIcon.cur")) // AND ENDS HERE
                {
                    _allOpsCursor = new Cursor(cursorStream);
                }
            }
            Mouse.SetCursor(_allOpsCursor);

            e.UseDefaultCursors = false;
            e.Handled = true;
        }
        finally { }
    }

i checked GetManifestResourceStream , but i still have no idea what a mainfest resource is how could it be handled and where to start to get this caching idea (mentioned in the main article) to work. 我检查了GetManifestResourceStream ,但是我仍然不知道什么是mainfest资源,如何处理它以及从哪里开始使该缓存思想(在主体文章中提到)起作用。

Your assembly is loaded into memory as part of the AppDomain executing under the CLR. 您的程序集作为在CLR下执行的AppDomain的一部分被加载到内存中。 Because of this, if the resource is embedded into the assembly as part of the compilation process, using a stream to read an in-memory byte array is faster than having to go to disk to open a file, read its contents, close the file. 因此,如果在编译过程中将资源嵌入到程序集中,则使用流读取内存中的字节数组要比必须进入磁盘打开文件,读取其内容,关闭文件要快。 。

Alternatives are to store a byte array representing the resource within the source code, though more or less you're arriving at the same place using GetManifestResourceStream . 替代方法是在源代码中存储表示资源的字节数组,尽管使用GetManifestResourceStream或多或少会到达同一位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM