这个问题的答案在哪里有用,谢谢我感谢帮助:)但我最终使用:http://code.msdn.microsoft.com/windowsdesktop/Handling-Unhandled-47492d0b#content
我想在应用程序崩溃时显示错误消息.
目前我有:
App.xaml
:
<Application x:Class="WpfApplication5.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DispatcherUnhandledException="App_DispatcherUnhandledException" // <----------------
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)
代码隐藏App.xaml
:
namespace WpfApplication5
{
public partial class App : Application
{
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
MessageBox.Show("Caught Unhandled Exception!");
}
}
}
Run Code Online (Sandbox Code Playgroud)
当主线程发生错误时,该解决方案很有效.现在我的问题是如何能够捕获在不同线程上发生的错误?
换句话说:当我按下此按钮时,我能够捕获异常:( App_DispatcherUnhandledException
被调用!)
private void button1_Click(object sender, RoutedEventArgs e)
{
int.Parse("lkjdsf");
}
Run Code Online (Sandbox Code Playgroud)
但是我无法捕捉到这个异常:
private void button1_Click(object sender, RoutedEventArgs e)
{
Task.Factory.StartNew(() =>
{
int.Parse("lkjdsf");
});
}
Run Code Online (Sandbox Code Playgroud)
无论它们是否发生在主线程上,我如何能够捕获所有异常?
我想创建一个非常简单的自定义原子包,我在其中突出显示基于正则表达式的特定单词.我正在处理处理大量ip地址的配置文件.我想将IP地址1.1.1.1的颜色设为红色,例如0.0.0.0蓝色......
创建包这么简单,这就是我所做的:
创建文件:
C:\Users\MyUsername\.atom\packages\MyPackage\package.json
{
"name": "language-conf",
"version": "0.0.1",
"description": "Syntax highlighting for configuration files",
"engines": {
"atom": "*"
}
}
Run Code Online (Sandbox Code Playgroud)
AND文件:
C:\Users\MyUsername\.atom\packages\MyPackage\grammars\rules.cson
'scopeName': 'source.conf'
'name': 'CONF'
'fileTypes': ['CONF']
'patterns': [
{
'match': '1\.1\.1\.1'
'name': 'constant.numeric.integer.hexadecimal.python'
},
{
'match': '0\.0\.0\.0'
'name': 'constant.numeric.integer.hexadecimal.python'
}
]
Run Code Online (Sandbox Code Playgroud)
当我打开配置文件时,它的外观如下:
注意ips是如何格式化的,这很棒!我怎样才能为不同的ips选择颜色?所有的ips都是黄色的.如果不是name属性,那么就会有一个颜色属性.
总之,我想设置这个例子的样式:
http://blog.gaku.net/create-a-custom-syntax-highlighting-with-atom-editor/
在该链接中,它没有向您展示如何将不同的颜色/样式放置到不同的规则.
我有一个类,通过传递一个对象列表填充ListView.该类使用反射来查看每个对象的属性,以便生成ListView.如何更改ListView中行的背景颜色.
这个页面完全符合我的要求.唯一的问题是我的ListView绑定到对象列表.换句话说,ListView的每个项都是绑定的对象而不是ListViewItem.我假设这就是我无法将ListView中的某些项目转换为ListViewItem的原因.例如,当我这样做时:
ListViewItem someItem = (ListViewItem)listView1.Items[0];
Run Code Online (Sandbox Code Playgroud)
我得到一个InvalidcastException,因为如果我将对象物理添加到ListView,如:
listview.items.add(someObject)然后这将工作,但因为我将列表绑定到ListView该行不起作用.我认为这就是我无法施展的原因.我想要转换它的原因是因为ListViewItem具有Background属性.
编辑
我能够用我尝试过的前12个对象来做到这一点:
for (int i = 0; i < listView1.Items.Count; i++)
{
var lvitem = listView1.ItemContainerGenerator.ContainerFromIndex(i) as ListViewItem;
lvitem.Foreground = Brushes.Green;
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
我也试过这个:
foreach (Tiro t in listView1.Items)
{
var lvitem = listView1.ItemContainerGenerator.ContainerFromItem(t) as ListViewItem;
if (t.numero == 0 || t.numero == 37)
{
//lvitem.Background = Brushes.Green;
lvitem.Foreground = Brushes.Green;
}
else if (t.numero % 2 == 0)
{
//lvitem.Background = Brushes.Red;
lvitem.Foreground = Brushes.Red;
}
else
{
//lvitem.Background …
Run Code Online (Sandbox Code Playgroud) 我有一个简单的C程序:
// it is not important to know what the code does you may skip the code
Run Code Online (Sandbox Code Playgroud)
main.c中
#include <bsp.h>
unsigned int AppCtr;
unsigned char AppFlag;
int SOME_LARGE_VARIABLE;
static void AppTest (void);
void main (void)
{
AppCtr = 0;
AppFlag = 0;
AppTest();
}
static void Foo(void){
SOME_LARGE_VARIABLE=15;
}
static void AppTest (void)
{
unsigned int i;
i = 0;
while (i < 200000) {
i++;
}
BSP_Test();
SOME_LARGE_VARIABLE=3;
Foo();
}
Run Code Online (Sandbox Code Playgroud)
bsp.c
extern int SOME_LARGE_VARIABLE;
extern unsigned char AppFlag; …
Run Code Online (Sandbox Code Playgroud) 我之前问过: 添加对visual studio宏的dll引用
用我的语言(C#)创建宏的想法使得创建宏更容易.问题是我无法调试dll
为了解决我试过的问题:
我myClassLibrary.pdb
接下来myClassLibrary.dll
希望我可以通过步入它们来调试dll中的方法.
创建了WCF服务.因为我不知道如何从vba引用服务,所以我从类库中引用它.问题是我需要使用变量,例如DTE.ActiveDocument
,这些变量不可序列化,这意味着我无法将它们传递给wcf服务.
在C#中工作的想法非常好但是无法调试并且看到发生了什么使得它有点困难.我可能不得不转到我的旧选项,我在C#上创建了我的代码然后用反射器反编译成vba.
我想我已经接近了解决方案.我想为什么不在控制台应用程序中创建宏?我能够获取活动文档文本但无法更改它.
EnvDTE80.DTE2 MyDte;
MyDte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject( "VisualStudio.DTE.10.0" );
Console.WriteLine( "The Edition is " + MyDte.Edition );
Console.ReadLine( );
// write to the console the text that is selected. "sometimes it does not work don't know why"
Console.WriteLine(
MyDte.ActiveDocument.Selection.Text
);
Run Code Online (Sandbox Code Playgroud)
注意我添加了以下引用加上vba宏具有的onces:
如何or
在不允许重复的情况下使用操作符?换句话说正则表达式:
(word1|word2|word3)+
Run Code Online (Sandbox Code Playgroud)
会匹配, word1word2
但也会匹配word1word1
我不想要的,因为word1正在重复.我该如何避免重复?
总之,我希望以下主题匹配:
word1word2word3
word1
word2
word3word2
Run Code Online (Sandbox Code Playgroud)
注意它们都匹配,因为没有重复.我希望以下主题失败:
word1word2word1
word2word2
word3word1word2word2
Run Code Online (Sandbox Code Playgroud)
感谢@Mark 我知道:
(?xi)
(?:
(?<A>word1|word2)(?! .* \k<A> ) # match for word1 or word2 but make sure that if you capture it it does not follow what it was just captured
| (?<B>word3|word4)(?! .* \k<B> )
)+
Run Code Online (Sandbox Code Playgroud)
因为我有兴趣看看是否在A组或B组中捕获了某些东西.
我正在编辑我的问题,我认为这有点令人困惑,并且不能解释我的意图。
我的目标是,当我的HelloWorld
应用程序引用MyClassLibrary
我的代码时,不会编译它们,因此我确保在运行main方法之前先初始化一些代码。有点像类的构造函数。当我引用MyClassLibrary
时,在运行HelloWorld
应用程序的main方法之前,我希望在其中运行一些代码。NUnit具有类似的功能。当我的HelloWorld
应用程序引用NUnit时,出现错误:Error CS0017 Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.
@Alex指出NUnit创建的Main方法是自动生成的。我想用一些自定义代码自动生成main方法。像NUnit一样,如何不对应用程序MyClassLibrary
执行任何操作就如何做到这HelloWorld
一点?
我要执行与NUnit
测试执行相同的行为,以防止使用某种Main
方法。在这种情况下,我需要的错误是一件好事。让我解释一下我的意思。
.net core
项目文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
代码文件:(默认的Hello World C#代码)
如果我随后运行该应用程序,它将运行正常
添加引用NUnit
,我的项目文件现在包含。
。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" …
Run Code Online (Sandbox Code Playgroud) 有几个地方讨论如何从文件扩展名中获取图标,例如这个和另一个.经过几个小时的这种项目,我设法建立了类似的东西:
private void addButton_Click(object sender, System.EventArgs e)
{
System.Drawing.Icon temp = IconReader.GetFileIcon(".cs", IconReader.IconSize.Large, false);
pictureBox1.Image = temp.ToBitmap();
}
Run Code Online (Sandbox Code Playgroud)
执行该按钮让我:
但我试图获得大图标.注意窗口上的图标是如何更大的:
我怎么能得到那个图标而不是较小的图标.我花了很多时间改变其他程序.此外,我想使用wpf,大多数示例都是使用Windows窗体.如果我能得到一个如何提取文件图标而不是修改整个项目的例子,我将不胜感激.如果这不可能仍然会非常有帮助,我将不胜感激.只是我不是一个程序员,我花了很多时间来修改其他的例子.
我知道如何更改滚动条的背景颜色:
<ScrollBar Height="27" Margin="36,96,12,0" Name="scrollBar1" Background="Red"></ScrollBar>
Run Code Online (Sandbox Code Playgroud)
这是我红色背景的图片:
我怎么能用ScrollViewer做同样的事情?我的ScrollViewer中有一个网格,如果我更改ScrollViewer的属性,它似乎会改变网格内容的属性.
<ScrollViewer>
<Grid Name="Parent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
....
....
... etc
Run Code Online (Sandbox Code Playgroud)
产生:
我的网格内容名为Parent,位于左侧.我怎么能在这个ScrollViewer上放置红色背景?