我有一个应用程序正在更改其他应用程序的某些设置(它是一个简单的C#应用程序,通过双击运行(无需安装)).
更改设置后,我需要重新启动其他应用程序,以便它反映更改的设置.
所以要做,我必须杀死正在运行的进程并再次启动进程,但问题是在杀死后我无法找到进程.(原因是系统不知道exe文件在哪里..)
有没有办法找出运行进程或exe的路径,如果它正在运行?
我不想手动给路径,即如果它正在运行获取路径,杀死进程并再次启动....我将稍后处理
是否可以在Visual Studio中调试Windows服务?
我用的代码就像
System.Diagnostics.Debugger.Break();
Run Code Online (Sandbox Code Playgroud)
但它给出了一些代码错误,如:
我收到两个事件错误:eventID 4096 VsJITDebugger和"服务没有及时响应启动或控制请求."
如何清除ConcurrentBag
?它没有像任何方法Clear
或RemoveAll
...
在我的项目中,我有两个以上具有相同签名的Main方法.一个是winForm,另一个是Console类.
如何将其中任何一个设置为入口点.
我[STAThread]
在一个主要方法之前声明设置入口点但它不起作用?
我正在使用Visual Studio Express 2010
以下CSharp代码(仅示例):
Console.WriteLine("Searching file in...");
foreach(var dir in DirList)
{
Console.WriteLine(dir);
}
Run Code Online (Sandbox Code Playgroud)
打印输出为:
Searching file in...
dir1
dir2
dir3
dir4
.
.
.
Run Code Online (Sandbox Code Playgroud)
题? 我怎样才能得到输出
Searching file in...
dir1
Run Code Online (Sandbox Code Playgroud)
(然后清除dir1并打印dir2等等)所有下一个目录名称wiil将替换之前的目录
创建一个COM服务器,然后我注册了它.
当我试图在COM客户端中添加该COM服务器时,我无法添加,并且出现以下错误.
"无法添加对'COMTest'的引用
ActiveX类型库'c\user \〜\ Debug\COMTest.tlb'是从.NET程序集导出的,无法添加为引用.
添加对.NET的引用"
任何人都可以告诉我这是什么错误.我以两种方式注册COM,也来自VS,也尝试使用命令提示符.
在我的应用程序中,我正在通过另一个线程(其他GUI线程)执行我的文件读取.有两个按钮分别挂起和恢复线程.
private void BtnStopAutoUpd_Click(object sender, EventArgs e)
{
autoReadThread.Suspend();
}
private void BtnStartAutoUpd_Click(object sender, EventArgs e)
{
autoReadThread.Resume();
}
Run Code Online (Sandbox Code Playgroud)
但我正面临这个警告,
Thread.Suspend已被弃用.请使用System.Threading中的其他类(如Monitor,Mutex,Event和Semaphore)来同步线程或保护资源. http://go.microsoft.com/fwlink/?linkid=14202
我怎么只运行单线程(而不是GUI线程),所以如何在这里应用同步或监控.
更新代码:
class ThreadClass
{
// This delegate enables asynchronous calls for setting the text property on a richTextBox control.
delegate void UpdateTextCallback(object text);
// create thread that perform actual task
public Thread autoReadThread = null;
public ManualResetEvent _event = new ManualResetEvent(true);
// a new reference to rich text box
System.Windows.Forms.RichTextBox Textbox = null;
private volatile bool _run; …
Run Code Online (Sandbox Code Playgroud) 我在xaml文件中创建了一个动画故事板.那个故事板从Button.Click开始.但是为了停止动画,我试图在代码背后的自定义事件上停止故事板.代码没有抛出任何异常但是当我的事件被触发时,动画仍然继续.
我认为问题在于Stop方法.停止需要与开始动画相同的对象来停止它.但是这里的故事板是从WPF xaml开始的,我在后面的代码中停止它.
任何解决方案,如何在代码中获取Xaml对象或任何替代解决方案?
XAML代码:
<Canvas.Triggers>
<EventTrigger RoutedEvent="Button.Click" SourceName="ScanButton">
<EventTrigger.Actions>
<BeginStoryboard >
<Storyboard Name="MovingServer" Storyboard.TargetName="ImageMove" RepeatBehavior="Forever" >
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:2" From="30" To="300" BeginTime="0:0:0" />
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:5" From="300" To="300" BeginTime="0:0:5" />
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Left)" Duration="0:0:2" From="300" To="600" BeginTime="0:0:7" />
<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:2" From="1" To="0" BeginTime="0:0:7" />
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
Run Code Online (Sandbox Code Playgroud)
代码背后:
private void EventPublisher_OnScanningFinish(object sender, EventArgs args)
{
Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { this.StopScanningAnimation(); });
}
private void StopScanningAnimation()
{
ServerView.StoryBoardServerScrolling.Stop(this); //---------- Not Working
//this.ServerView.Server1Static.Visibility = System.Windows.Visibility.Hidden;
//this.ServerView.Server2Static.Visibility = System.Windows.Visibility.Hidden;
//this.ServerView.Server3Scrolling.Visibility = System.Windows.Visibility.Hidden; …
Run Code Online (Sandbox Code Playgroud) 如何根据匹配的属性值删除xml中的任何元素?
这是我的XML:
<Projects>
<Project serverUrl="tcp://xyz1:xxx/sdfsdf.rem" projectName="project1" />
<Project serverUrl="tcp://xyz2:xxx/sdfsdf.rem" projectName="project2" />
<Project serverUrl="tcp://xyz3:xxx/sdfsdf.rem" projectName="project3" />
<Project serverUrl="tcp://xyz4:xxx/sdfsdf.rem" projectName="project4" />
<Project serverUrl="tcp://xyz5:xxx/sdfsdf.rem" projectName="project5" />
<Project serverUrl="tcp://xyz6:xxx/sdfsdf.rem" projectName="project6" />
</Projects>
Run Code Online (Sandbox Code Playgroud)
我使用以下LINQ查询:
var remove = from elemet in xdoc.Elements("Projects").Elements("Project")
where elemet.Attribute("projectName").Value == "project1"
select elemet.Parent.Remove();
Run Code Online (Sandbox Code Playgroud)
我在select上得到编译时错误:
select子句中的表达式类型不正确
编辑答案:这个对我有用.谢谢大家
var xElement = (from elemet in xdoc.Elements("Projects").Elements("Project")
where elemet.Attribute("projectName").Value == foundProject
select elemet);
xElement.Remove();
Run Code Online (Sandbox Code Playgroud) 我正在使用正则表达式来检查子网掩码.我使用带有屏蔽值的ajax txtbox,但这不起作用,然后我切换到文本框并为其应用正则表达式.不幸的是,一个人也没有工作.
你能帮助我为子网屏蔽255.255.255.255提供RE吗?
或者最好的方法呢?
方案:
我使用蒙面文本框,不知道如何放置验证表达式.
最后,我发现了一个蒙版文本框的属性作为验证表达式,然后我把RE和属性validate更改为true.
无需显式使用验证器表达式.
谢谢
c# ×10
.net ×1
asp.net ×1
com ×1
com-interop ×1
concurrency ×1
deadlock ×1
interop ×1
linq ×1
linq-to-xml ×1
monitoring ×1
wpf ×1
xml ×1