我收到错误使用泛型类型'System.Collections.Generic.Dictionary <TKey,TValue>'需要使用以下代码行的2个类型参数:
this._logfileDict = new Dictionary();
Run Code Online (Sandbox Code Playgroud)
我只是想在我的代码中有一个明确的_logfileDict没有条目,所以这就是为什么我给它分配一个新的Dictionary,它将是空的,但是如果有人知道一些代码,我可以用它来清空_logfileDict.它只是一个字典声明如下:
private Dictionary<string, LogFile> _logfileDict;
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢!
有谁知道是否可能/如何使用 ProcDump 获取 Windows 服务的转储?我想要运行的命令是这样的:
ProcDump -e -mp -x myservice.exe mydump.dmp
Run Code Online (Sandbox Code Playgroud)
但是,我收到“无法从命令行或调试器启动服务”消息。有谁知道是否有办法解决这个问题?
我有这行代码:
System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
Run Code Online (Sandbox Code Playgroud)
几行之后,在使用图标之后我有了这条线:
Win32.DestroyIcon(shinfo.hIcon);
Run Code Online (Sandbox Code Playgroud)
但是,当对我的代码运行静态分析时,它表示Resource_Leak可能来自图标.我想知道如果我调用dispose方法会有什么不同:
icon.Dispose();
Run Code Online (Sandbox Code Playgroud)
而不是现在正在使用的Win32.DestroyIcon().它们之间有什么区别吗?我只是维护这段代码所以我不确定原始开发人员是否有任何使用Win32.DestroyIcon的特殊内容.
我试图使用正则表达式对字符串做一些工作,但我遇到了一些困难.我的目标是用字符替换字符串中的数字,特别是如果字符串中有一组数字我想用a替换整个数字组*.如果只有一个数字我想用a替换它?.
例如,如果我有字符串"test12345.txt",我想将其转换为"test*.txt",但如果我有"test1.txt",我想将其转换为"test?.txt" .
我试过了
Regex r = new Regex(@"\d+", RegexOptions.None);
returnString = r.Replace(returnString, "*");
Run Code Online (Sandbox Code Playgroud)
但这取代了一个单独的数字,而不是一个数字 *
我有以下代码:
RegistryKey installKey = Registry.LocalMachine.OpenSubKey(installKey);
Run Code Online (Sandbox Code Playgroud)
我在我的代码上运行一个静态分析工具,它给了我一个缺陷,说我从没有处理installKey的方法返回.我知道您可以在.NET 4.0或更高版本的RegistryKey上调用Dispose(),但我的代码在.NET 3.5上运行.
有没有人知道处理这个RegistryKey并让我的静态分析工具满意的最佳方法?
我正在尝试学习模板,我希望我的类对能够容纳任何类型的两个对象.我现在只想为obj1提供一个访问器功能.但是当我尝试complile时,我收到以下错误:
error: expected initializer before '<' token
T1 pair<T1,T2>::getObj1()
Run Code Online (Sandbox Code Playgroud)
我的代码是:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
template <class T1, class T2>
class pair
{
public:
pair(const T1& t1, const T2& t2) : obj1(t1), obj2(t2){};
T1 getObj1();
private:
T1 obj1;
T2 obj2;
};
template <class T1, class T2>
T1 pair<T1,T2>::getObj1()
{
return obj1;
}
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud) 在一个应用程序中,我注册了EventLog.EntryWritten事件,并使用.NET Threadpool线程等待更改事件发生.我认为这个.NET Threadpool线程中发生异常,所以我想使用try/catch来确保,如下所示:
try {
eventLog.EntryWritten += new EntryWrittenEventHandler(EventLogMonitor);
}
catch (System.Componentmodel.Win32exception e)
{
// log error
}
Run Code Online (Sandbox Code Playgroud)
我只是想知道我是否在正确的地方使用try/catch来监视此线程的异常?
我只是想从XML文件中读取一些细节,其中一部分如下所示:
<appender name="FILE" class="applications.core.logging.CustomFileAppender">
<param name="File" value="C:\\Logs\\File.log"/>
<param name="MaxBackupIndex" value="5"/>
</appender>
<appender name="FILE" class="applications.core.logging.CustomFileAppender">
<param name="File" value="C:\\Logs\\File2.log"/>
<param name="MaxBackupIndex" value="17"/>
</appender>
<appender name="FILE" class="applications.core.logging.CustomFileAppender">
<param name="File" value="C:\\Logs\\File3.log"/>
<param name="MaxBackupIndex" value="98"/>
</appender>
Run Code Online (Sandbox Code Playgroud)
我的XML文件中有几个'appender'节点.以下代码循环遍历每个'appender'节点.在每个"appender"中,我想要选择名为"File"的param节点,并检查该值是否等于我要查找的值.
foreach (XElement node in XmlFile.Descendants("appender"))
{
IEnumerable<XElement> elements = from el in node.Elements("param")
where el.Attribute("value").ToString().Equals("C:\\Logs\\File.log"))
select el;
foreach (XElement el in elements)
{
Console.WriteLine("Found it " + el.Name);
// Now read value for MaxBackupIndex
}
}
Run Code Online (Sandbox Code Playgroud)
但是我的代码没有打印出来,所以我想可能我的LINQ查询的"where"部分是不正确的,任何人都可以找到我错的地方吗?
我只是想在我的Android应用程序上的相机预览上画一个正方形.相机预览显示在SurfaceView上,从我在线阅读看来,实现此目的的最佳方法是将另一个SurfaceView放置在相机Feed显示的那个上并在其上绘制.所以我添加了这个并且还添加了一些代码,但它不起作用,我看到相机提供没有问题但是方块永远不会被绘制.只是想知道是否有人对我错过的东西有任何想法.我的DrawFocusRect函数被调用,它只是我的矩形永远不会出现.
我的布局xml文件中的表面视图
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="vertical" >
<SurfaceView
android:id="@+id/full_colour"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
<SurfaceView
android:layout_alignParentTop="true"
android:id="@+id/TransparentView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我的绘图代码,从onPreviewFrame调用
private static void DrawFocusRect()
{
int hWidth = transparentView.getWidth();
int hHeight = transparentView.getHeight();
float f = (float) 0.5;
float rLeft = (float) Math.floor(((1-f)/2)*hWidth);
float rRight = (float) Math.floor((((1-f)/2)+f)*hWidth);
float rTop = (float) Math.floor(((1-f)/2)*hHeight);
float rBottom = (float) Math.floor((((1-f)/2)+f)*hHeight);
canvas = holderTranspaernt.lockCanvas();
canvas.drawColor(Color.GREEN, Mode.CLEAR);
//border's properties
paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.YELLOW);
paint.setStrokeWidth(3);
canvas.drawRect(rLeft, rTop, rRight, rBottom, paint);
holderTranspaernt.unlockCanvasAndPost(canvas);
}
Run Code Online (Sandbox Code Playgroud) 我编写了一个C#工具,它将通过在命令提示符中为我多次运行一个命令来启动一个应用程序.为我这样做的代码如下:
System.Diagnostics.Process.Start("CMD.exe", strCmdText);
Run Code Online (Sandbox Code Playgroud)
所以我有一个循环,一切都很好.但是每次执行时都会打开一个新的命令窗口,这是不理想的.有没有办法在命令执行后关闭命令窗口,或者更好的是,根本没有打开命令窗口?任何帮助真的很感激!!
c# ×7
dispose ×2
android ×1
c++ ×1
dictionary ×1
exception ×1
linq-to-xml ×1
procdump ×1
regex ×1
registrykey ×1
service ×1
string ×1
surfaceview ×1
templates ×1
threadpool ×1
try-catch ×1
xml ×1