我有这个方法:
private delegate void watcherReader(StreamReader sr);
private void watchProc(StreamReader sr) {
while (true) {
string line = sr.ReadLine();
while (line != null) {
if (stop) {
return;
}
//Console.WriteLine(line);
line = stripColors(line);
txtOut.Text += line + "\n";
line = sr.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
它从进程(cmd.exe)读取流.当用户关闭cmd.exe窗口时,它会导致CPU使用率跳至100%.在使用调试器时,我看到它在sr.ReadLine()上停止并且永远不会返回.因为它正在观察StandardErrorStream和StandardOutputStream,所以它在两个核心上都使用100%.
如果需要,这里有一些项目代码.
[DllImport("User32")]
private static extern int ShowWindow(int hwnd, int nCmdShow); //this will allow me to hide a window
public ConsoleForm(Process p) {
this.p = p;
p.Start();
ShowWindow((int)p.MainWindowHandle, 0); //0 means to hide the window.
this.inStream = …Run Code Online (Sandbox Code Playgroud) 我已经创建了一个自定义线程池实用程序,但似乎有一个我找不到的问题.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
namespace iWallpaper.S3Uploader
{
public class QueueManager<T>
{
private readonly Queue queue = Queue.Synchronized(new Queue());
private readonly AutoResetEvent res = new AutoResetEvent(true);
private readonly AutoResetEvent res_thr = new AutoResetEvent(true);
private readonly Semaphore sem = new Semaphore(1, 4);
private readonly Thread thread;
private Action<T> DoWork;
private int Num_Of_Threads;
private QueueManager()
{
Num_Of_Threads = 0;
maxThread = 5;
thread = new Thread(Worker) {Name = "S3Uploader EventRegisterer"};
thread.Start();
// log.Info(String.Format("{0} [QUEUE] FileUploadQueueManager created", DateTime.Now.ToLongTimeString()));
} …Run Code Online (Sandbox Code Playgroud) 我想在一个aspx.cs文件中使用一个字符串,而不是另一个.我知道这很容易,但我该怎么做呢?
我想开发一个可以隐藏文件夹的程序.不是隐藏属性,而是真正的隐藏,以便没有应用程序可以找到它.我认为我需要创建一个文件系统驱动程序.
我怎么能在C#中做到这一点?
Delphi有没有好的图片,照片浏览器或轮播控件?
如果有的话,我更喜欢免费的东西.
有人可以推荐一些优秀的VB.net代码生成工具吗?
我只需要一个开发桌面应用程序的工具.所以事情的网络方面并没有太多关注我.
我正在研究用Java实现的模式,并且有一些关于它如何与C#对齐(可以移植到)的问题.
Java的:
class Foo
{
private Class someClass;
...
}
class Bar
{
private Field some Field;
}
Run Code Online (Sandbox Code Playgroud)
首先,Class存储域对象的实例.看起来Java在类型上公开了反射方法,用于通过反射访问对象上的字段.什么类型将成为C#的同义词?我会使用对象然后使用MethodInfo还是有更好的方法?
其次,Field是框架中的类型,使用以下方式分配:
someClass.getDeclaredField(fieldName)
Run Code Online (Sandbox Code Playgroud)
我应该使用.NET框架中的并行吗?
现在我创建了一个自定义对象来代替Foo中的Class,我为Field创建了一个自定义对象.有没有一种首选的方法呢?
任何人都可以想到一种有效的方法(时间明智)从字符串中间修剪几个选定的字符?
我想出的最好的是:
public static string Trim(this string word, IEnumerable<char> selectedChars)
{
string result = word;
foreach (char c in selectedChars)
result = result.Replace(c.ToString(), "");
return result;
}
Run Code Online (Sandbox Code Playgroud)
但它仍然太慢.
在我编写的每个ASP.NET应用程序中,在将信息输出到网页之前,我会向数据库发出一些请求.
例如:
var DataTable1 = GetDataTable("Select * From Customers");
var DataTable2 = GetDataTable("Select * From Products");
var DataTable3 = GetDataTable("Select * From Orders");
Run Code Online (Sandbox Code Playgroud)
据我所知,上面的代码将进行3次单独的数据库访问,并将一个接一个地执行.
无论如何,我可以聚集我的参数化SQL语句,只有1次数据库服务器之旅?
c# ×6
.net ×4
asp.net ×2
controls ×1
delegates ×1
delphi ×1
filesystems ×1
html ×1
java ×1
lambda ×1
performance ×1
readline ×1
reflection ×1
sql ×1
streamreader ×1
string ×1
vb.net ×1