当一个字段用于创建另一个字段,然后处理 - 我看到两个选项.第一:
Image image = Image.FromFile(path);
Bitmap bitmap = (Bitmap)image.GetThumbnailImage(32, 32, null, new IntPtr());
image.Dispose();//not needed anymore.
//use bitmap
bitmap.Dispose();
Run Code Online (Sandbox Code Playgroud)
第二:
using (Image image = Image.FromFile(path))
{
using (Bitmap bitmap = (Bitmap)image.GetThumbnailImage(32, 32, null, new IntPtr()))
{
//use bitmap
}
}
Run Code Online (Sandbox Code Playgroud)
逻辑1将是第一个(因为在使用Image时不需要Bitmap),但using语句通常优先于Dispose.
还有第三种方法 - using在第二种方式中终止第一种方式吗?
还有我的程序能够发送从一部分到另一部分,如信息DragEnter来GiveFeedback改变光标.使用变量作为标志很容易做到这一点.但是 - 如果用户启动了该程序的多个实例,该怎么办?
一种方法是将信息写入文件,但最好尽可能少地执行磁盘操作.另一种方法是使用管道,但如果有很多程序实例,它似乎有点复杂.还有另外一种方法吗?
我想将字符串转换为XML.当然我可以这样做:
"<node Attribute1="att1">" + MyString + "</node>"
Run Code Online (Sandbox Code Playgroud)
但是,如果在.net中存在某些东西,为什么要重新发明轮子呢?是否有一个方法采用节点名称,属性和内部XML并返回XML字符串?
我需要一个Exception既接收消息又int作为参数的类,而宁愿使用现有的类而不是创建我自己的自定义派生异常.
我一直在寻找一个,但它比我想象的更难.
有没有这样的(通常命名的)课程?
编辑
我打算抓住它并显示:"Error " + ex.Message + ex.Code.ToString();.
错误代码用于我不想向用户显示的消息.(用于调试的技术内容等.将显示错误代码, 以便用户可以告诉我他得到了什么代码.)
我更喜欢现有Exception的原因是我希望在我的所有应用程序中都有统一的方法来处理异常,而不必每次都定义它们.
使用以下代码:
HttpListener listener = new HttpListener();
//listener.Prefixes.Add("http://*:80/");
listener.Prefixes.Add("http://*:8080/");
listener.Prefixes.Add("http://*:8081/");
listener.Prefixes.Add("http://*:8082/");
listener.Start();
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;
Run Code Online (Sandbox Code Playgroud)
GetContext();尽管在 IE 和 Firefox 中加载 http(不是 https)页面,但该程序仍会挂起。
当我取消注释第一行时,出现错误:
无法侦听前缀“http://*:80/”,因为它与计算机上的现有注册冲突。
那么如何监听浏览器的请求呢?
我有一个针对.net标准1.4的Xamarin.Forms应用程序.在具有最低版本14393(和目标16299)的UWP应用程序上,我从Microsoft Store获得以下异常(尽管在我的计算机上它甚至从appxbundle文件运行良好):
注意要点:
Xamarin.Forms.Forms.Init(e);在OnLaunched.Could not load file or assembly 'System.Private.CoreLib...'.System.IO.FileNotFoundException:无法加载文件或程序集'System.Private.CoreLib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.该系统找不到指定的文件.文件名:System.ModuleHandle.ResolveType的'System.Private.CoreLib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'(RuntimeModule模块,Int32 typeToken,IntPtr*typeInstArgs,Int32 typeInstCount,IntPtr*methodInstArgs,Int32 methodInstCount System.FoduleHandle.ResolveTypeHandleInternal(RuntimeModule模块,Int32 typeToken,RuntimeTypeHandle [] typeInstantiationContext,RuntimeTypeHandle [] methodInstantiationContext),System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken,Type [] genericTypeArguments,Type [] genericMethodArguments)at,SystemHandleOnStack type) System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord,MetadataImport范围,Assembly&lastAptcaOkAssembly,RuntimeModule decoratedModule,MetadataToken decoratedToken,RuntimeType attributeFilterType,Boolean mustBeInheritable,Object [] attributes,IList derivedAttributes,RuntimeType&attributeType,IRuntimeMethodInfo&ctor,Boolean&ctorHasParameters ,布尔逻辑isVarArg)处System.Reflection.CustomAttribute.GetCustomAttributes System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule,的Int32 decoratedMetadataToken,的Int32 pcaCount,RuntimeType attributeFilterType,布尔mustBeInheritable,IList的derivedAttributes,布尔isDecoratedTargetSecurityTransparent)(RuntimeAssembly组件,RuntimeType caType)在System.Attribute.GetCustomAttributes(Assembly element,Type attributeType,Boolean inherit)的System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType,Boolean inherit)位于Xamarin.Forms的Xamarin.Forms.Internals.Registrar.RegisterAll(Type [] attrTypes) PasswordManager.UWP.App.d__1.MoveNext()中的.Forms.Init(IActivatedEventArgs launchActivatedEventArgs,IEnumerable`1 rendererAssemblies)
任何想法可能意味着什么,以及如何解决它?
这一切都在标题中.A ComboBox由一个IEnumerable类型填充SomeType.如何ComboBox确定每个项目将显示哪些文本?
当然,我不是在询问类型的情况string.