我有一个条件,我需要关闭应用程序,所以我设置一个certian标志时调用this.Dispose().
起初我认为在调用this.Dispose()之后调用函数是一个问题,因此我将代码移动到最后调用的东西,但我仍然得到"ArgumentException未处理""参数无效".在Application.Run(new myApp();行.
我究竟做错了什么?我一路上都错过了什么吗?或者可能有更好的方法来关闭应用程序?
我正在使用WPF的ProgressBar对象,它具有Value属性,我可以传递一个常量的int或十进制值,它不会抱怨,但如果我传递一个float(或int或string)变量值,它会barfs一个ArgumentException(例如"Message='0.02380952' is not a valid value for property 'Value'.")在我身上,这对我来说似乎是荒谬的,让我难过.我跟随的MS示例使用常量浮点值.然而,MS文档对Value属性的引用表示它是一个int,这似乎是错误的,因为我可以将它传递给常量.1或.5并获得正确的行为,而我的MS示例使用0和1以及最小值和最大值.那么,我需要做什么呢?
我的代码:
XAML:
<ProgressBar x:Name="prgProgress" Width="200" Height="20" Minimum="0" Maximum="100" />
Run Code Online (Sandbox Code Playgroud)
C#:
float numMems = ListToShow.Count;
float numDone = 0.0f;
int fracDone = 0;
string sProgress = "0%";
foreach (RAM_Member mem in ListToShow)
{
if (isCanceled == true) break;
mem.CalculateValues();
numDone++;
fracDone = (int)(100.0 * numDone / numMems);
sProgress = (100 * numDone / numMems).ToString("0.") + "%";
Dispatcher.BeginInvoke(DispatcherPriority.Background, (SendOrPostCallback)delegate { prgProgress.SetValue(ProgressBar.ValueProperty, fracDone); }, null);
Dispatcher.BeginInvoke(DispatcherPriority.Background, (SendOrPostCallback)delegate { …Run Code Online (Sandbox Code Playgroud) 我需要捕获一个特定的ArgumentException.
System.ArgumentException:输入数组长于此表中的列数.
我注意到可能会出现一些ArugmentExceptions,但我将如何专门捕获这个?"输入数组比此表中的列数长"
不幸的catch(ArgumentException ex)是做的不够具体......
我们正在上传制表符分隔文件,上面的例外告诉我们告诉用户检查文件中的列数并再试一次.
这个问题是关于约定和解释MSDN的,所以我不认为它主要是基于意见的.
我想知道ArgumentException:我有一个构建器类,用于构建一个过滤器对象,该过滤器对象将在从邮箱中检索一组电子邮件时应用.构建器有许多方法可以设置过滤器选项.例如,我有两种设置过滤器"发送日期"范围的方法 - 在XX之前发送和/或在XX之后发送.我想为每个添加一个保护条款,如果提供的"之前"日期在提供的"之后"日期之后,则会抛出异常.我会用一个通用的验证方法来做到这一点:
/// <summary>
/// This class provides methods for validating dates in various ways.
/// </summary>
internal static class DateValidation
{
/// <summary>
/// Validate the provided "start" and "end" date/time values.
/// If they do not represent a valid range, throw an exception.
/// </summary>
/// <param name="start">The date/time that represents the start of the range.</param>
/// <param name="end">The date/time that represents the end of the range.</param>
internal static void …Run Code Online (Sandbox Code Playgroud) 我有以下 Powershell 代码,使 Chrome 在单击任务栏上的固定图标时始终使用默认配置文件打开:
$shortcutPath = "$($Env:APPDATA)\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Google Chrome.lnk"
$shell = New-Object -COM WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath) ## Open the lnk
$shortcut.TargetPath
if ($shortcut.TargetPath.EndsWith("chrome.exe")) {
$shortcut.TargetPath = """$($shortcut.TargetPath)"" --profile-directory=""Default"""
$shortcut.Save() ## Save
}
Run Code Online (Sandbox Code Playgroud)
执行时,该if语句抛出以下错误:
Value does not fall within the expected range.
At line:2 char:31
+ $shortcut.TargetPath = """$($shortcut.TargetPath)"" --profile-direc ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException
Run Code Online (Sandbox Code Playgroud)
为什么我会出现上述错误?以及如何修复它?感谢!
我有一个让我疯狂的问题.我正在使用一个泛型List,每当我尝试将其第一个(或最后一个?)索引分配给变量时,它会抛出ArgumentOutOfRangeException.这是一大堆代码,因此我将尝试仅提取相关内容.所以这里是:
private string GetRuleByName(string name, List<string> rules)
{
if(rules != null)
{
List<string> todo = new List<string>();
todo.AddRange(rules);
while(rules.Count != 0)
{
string r = todo[0]; // <- Error 'ArgumentOutOfRangeException' here
todo.RemoveAt(0);
// ...
}
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我称之为方法的方式:
void treeView_AfterSelect(object sender, TreeViewEventArgs e)
{
string currentRule = GetRuleByName(treeView.SelectedNode.FullPath, ruleCollection)
// the string list "ruleCollection" always contains
// strings and thus is never empty
}
Run Code Online (Sandbox Code Playgroud)
虽然它不是一个非常详细的介绍正在发生的事情,因为我不得不切断一些复杂的代码,我真的希望别人可能会看到产生错误的原因.
非常感谢提前至少看看!
编辑:
这就是方法的样子.我没有改变任何东西,以显示其中的真实内容.我希望对某些人有意义:
private Rule GetRuleByNameOrId(string stName, List<Rule> rules)
{
if(rules != null)
{ …Run Code Online (Sandbox Code Playgroud) 这个错误是什么?我正在写一个新的程序,但我看到一个错误bur我不知道它是什么!!http://rozup.ir/up/salardesigner/Pictures/eror.png