小编Mar*_*cus的帖子

在"使用"块中是SqlConnection在返回或异常时关闭?

第一个问题:
说我有

using (SqlConnection connection = new SqlConnection(connectionString))
{
    connection.Open();

    string storedProc = "GetData";
    SqlCommand command = new SqlCommand(storedProc, connection);
    command.CommandType = CommandType.StoredProcedure;
    command.Parameters.Add(new SqlParameter("@EmployeeID", employeeID));

    return (byte[])command.ExecuteScalar();
}
Run Code Online (Sandbox Code Playgroud)

连接是否关闭?因为从技术上讲,我们永远不会}return以前那样到达最后.

第二个问题:
这次我有:

try
{
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        int employeeID = findEmployeeID();

        connection.Open();
        SqlCommand command = new SqlCommand("UpdateEmployeeTable", connection);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add(new SqlParameter("@EmployeeID", employeeID));
        command.CommandTimeout = 5;

        command.ExecuteNonQuery();
    }
}
catch (Exception) { /*Handle error*/ }
Run Code Online (Sandbox Code Playgroud)

现在,说出来try我们得到一个错误,它被抓住了.连接是否仍然关闭?因为我们再次跳过其余代码try并直接转到catch …

c# using sqlconnection

134
推荐指数
5
解决办法
16万
查看次数

Process.Kill()vs Process.Start("taskkill",...)

我有一个小的C#安装程序应用程序,我想杀死一个进程.使用中是否有任何优点/差异

Process[] procs = Process.GetProcessesByName("[taskname]");
foreach (Process p in procs) { p.Kill(); }
Run Code Online (Sandbox Code Playgroud)

VS

Process.Start("taskkill", "/F /IM [taskname].exe");
Run Code Online (Sandbox Code Playgroud)

我在某处读到使用"taskkill"只能在XP(和更高版本)中使用,那么这样会Process.Kill()更安全吗?

c# process

19
推荐指数
2
解决办法
2万
查看次数

如果用户= SYSTEM,.NET用户设置存储在哪里?

我一直在使用更新来更新我的一个应用程序并使用Properties.Settings.Default.Upgrade()并发现在我的updater重新启动我的应用程序后,它在SYSTEM用户下运行而不是默认/登录用户.

这让我想知道,SYSTEM的user.config存储在哪里?
我知道user.config正常存储的位置(C:\Documents and Settings\%USERPROFILE%\Local Settings\Application Data\etc...),但Documents and SettingsSYSTEM用户没有文件夹.有人知道它在哪里或/ .NET如何处理这个问题?

c# settings system

11
推荐指数
1
解决办法
2024
查看次数

Repsonse.Transmitfile(); 能够节省但无法打开

我正在尝试使用发送xlsx文件

Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/vnd-ms.excel";
Response.TransmitFile(file.FullName);
Response.End();
Run Code Online (Sandbox Code Playgroud)

弹出IE对话框,我可以成功保存文件,然后从文件夹打开它,工作正常和花花公子.但如果我在IE对话框中单击"打开",我会收到"无法下载myFile.xlsx".我单击"重试"并打开Excel但弹出"Excel无法打开文件'myFile.xlsx',因为文件格式或文件扩展名无效..."错误.
我目前正在调试模式下从VS2010运行该站点.

有谁知道为什么它会让我保存,但不能直接打开?

编辑
Chrome只需下载它.FF尝试打开它但是给出错误The file you are trying to open, 'myFile.xlsx.xls', is in a different format than specified by the file extension...我可以选择打开它并且它成功打开,但是在只读模式下.
所以,这里有一些时髦的东西.
fileName ="myFile.xlsx"

编辑2
这是在IE 9中.我也尝试过octet-streamapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet作为ContentType.

c# asp.net response.transmitfile

8
推荐指数
1
解决办法
5978
查看次数

生产中WCF"太多活动安全协商"错误

我们有一个WCF服务,超过100个客户端站点拨打电话.今天我们开始了

Exception: Server 'http://[url]/services/[service].svc/ws' sent back a     
fault indicating it is too busy to process the request. Please retry later. Please see the 
inner exception for fault details.
System.ServiceModel.FaultException: There are too many active security negotiations or 
secure conversations at the service. Please retry later.
Run Code Online (Sandbox Code Playgroud)

我能找到的唯一信息是我需要制作maxPendingSessions更大的信息.但这需要将端点更改为CustomBinding,这将很难,因为我必须将其推送到我的所有客户端站点.

有什么方法可以"重置"安全谈判的数量等等?这将使我们有时间更改客户端程序以使用自定义绑定,因为目前,我们的站点无法与我们的服务器通信.
我已经尝试对配置文件进行一些小的更改并保存,这应该重新启动了服务,但我们仍然遇到错误.

还是有其他方法我可以处理这个?

编辑这是我的配置:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,     Microsoft.Practices.EnterpriseLibrary.Data"/>
  </configSections>
  <connectionStrings>
  </connectionStrings>
    <system.web>
      <compilation debug="true" targetFramework="4.0"/>
      <authorization>
        <allow users="?"/>
      </authorization>
    </system.web>

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Error" propagateActivity="true">
        <listeners> …
Run Code Online (Sandbox Code Playgroud)

wcf config exception

6
推荐指数
1
解决办法
3036
查看次数

试图抓住Volume onKeyLongPress()无法正常工作

我正在尝试通过以下代码让我的应用程序对音量下调的长按键做出反应:

public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        Log.w("myApp", "LONG PRESS");
    }
    return super.onKeyLongPress(keyCode, event);
}
Run Code Online (Sandbox Code Playgroud)

但是,它只onKeyPress()会使一堆事件发生故障,而且onKeyLongPress()永远不会被调用.我的目的是让音量降低,单独"短"按下,让我的应用程序对长按音量做出不同的反应.
任何人都可以指出我错过了什么吗?

android onkeypress

6
推荐指数
1
解决办法
5953
查看次数

EventSetter用于非路由事件?

我有一个Label我正在尝试更改MouseDown事件,如果用户登录或不使用Trigger.

<Label x:Name="lblSave" MouseDown="lblSave_MouseDown" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5" ToolTip="Save Files"  Width="25" Height="25" Margin="0, 0, 5, 0"  >
<Label.Style>
    <Style TargetType="{x:Type Label}">
        <Setter Property="Background" Value="{DynamicResource ResourceKey=saveIcon}" />
        <Style.Triggers>
            <DataTrigger Binding="{Binding Source={x:Static sec:Security.Instance}, Path=IsLoggedIn}" Value="False">
                <Setter Property="Background" Value="{DynamicResource ResourceKey=readonlyIcon}" />
                <EventSetter Event="MouseDown" Handler="lblNoAccess_MouseDown" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Label.Style>
Run Code Online (Sandbox Code Playgroud)

但是,与这篇文章相反,我所拥有的东西不会起作用,因为MouseDown它不是一个路由事件.我仍然得到System.Windows.EventSetter.Event错误:{"Value cannot be null.\r\nParameter name: value"}.

所以我的问题是,有没有办法使用触发器来设置非路由事件?

wpf xaml triggers styles event-handling

6
推荐指数
1
解决办法
3304
查看次数

有没有办法告诉WCF服务有多少"并发呼叫"?

我有一个WCF服务,目前11个客户端每隔3分钟ping一次.他们都运行了好几个星期.昨晚,由于超时,他们突然停止了.所以我查看了我的服务器web.config.特别:

<serviceThrottling maxConcurrentCalls ="50" maxConcurrentSessions="200"/>
Run Code Online (Sandbox Code Playgroud)

这应该没有问题.
我将两个值都更改为500,保存文件,一切都重新开始了.因此,制作多少连接一定存在问题.
我的问题是:有没有办法在服务器应用程序上查看当前有多少并发调用?像某种监控系统?这将帮助我找到为什么50个可能的呼叫对11个客户来说不够.


问题2:编辑服务的web.config,然后保存它,重置所有连接?或者只是我让并发呼叫更大?

c# wcf timeout

5
推荐指数
1
解决办法
1012
查看次数

有没有办法在 Android 上预加载 AdMob 广告?

我在我的应用程序的“对话框”中有一个 AdMob 广告(我创建的视图看起来像一个视图,因为广告不适合普通对话框)。通常在广告加载前大约需要 4 或 5 秒,而且由于它位于“对话框”中,用户很可能会在广告加载前点击按钮(关闭对话框)。
有没有办法可以预加载广告,以便它们在包含视图创建后立即显示?

android preload admob

5
推荐指数
1
解决办法
5211
查看次数

我不明白WCF扩展安全性/为什么lsass.exe CPU%这么高?

我有一个WCF服务,大约有500个客户端每3分钟拨打一次电话.服务打开时,lsass.exe进程使用95%的CPU.
我做了一个测试,每次客户端拨打电话时,lsass CPU%上升到大约7左右.所以我理解为什么当几百个同时发送呼叫时服务器正在减慢呼叫速度.
我不明白,为什么lsass被使用呢?我正在使用基于WSHttpBinding的CustomBinding和使用证书的消息级安全性.实例/并发是PerCall/Single(尽管我已经尝试了两者的几乎所有组合而没有变化),并且它是在IIS 6中托管的.
我的猜测是,对于每次调用,lsass都在检查证书,这不知何故需要很多CPU?有什么方法可以减轻这个吗?我知道人们已经将WCF服务扩展到更大的数字,那么我做错了什么呢?

PS一些额外的信息:我有跟踪,通常记录的第一件事是

<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Warning">
    <TraceIdentifier>http://msdn.microsoft.com/en-US/library/System.ServiceModel.Activation.WebHostNoCBTSupport.aspx</TraceIdentifier>
        <Description>Extended protection is not supported or not enabled on this platform. Please install the appropriate patch and enable it if you want extendedProtection support for https with windows authentication.</Description>
        <AppDomain>/LM/W3SVC/920256058/Root/WCFServices/smt-7-129642078492968750</AppDomain>
        <Source>System.ServiceModel.Activation.MetabaseSettingsIis6/17731154</Source>
</TraceRecord>
Run Code Online (Sandbox Code Playgroud)

而且还有一堆:

http://msdn.microsoft.com/en-US/library/System.ServiceModel.Security.SecuritySessionDemuxFailure.aspx
The incoming message is not part of an existing security session.
Run Code Online (Sandbox Code Playgroud)

<ExceptionType>System.ServiceModel.Security.SecurityNegotiationException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
<Message>Cannot find the negotiation state for the context 'uuid-4caa56ff-3d38-4905-9151-ce12acdd676c-6778'.</Message>
Run Code Online (Sandbox Code Playgroud)

<NegotiationTokenAuthenticator>System.ServiceModel.Security.TlsnegoTokenAuthenticator</NegotiationTokenAuthenticator>
<AuthenticatorListenUri>http://myserviceendpoint</AuthenticatorListenUri>
<Exception>System.ServiceModel.Security.SecurityNegotiationException: Cannot find the negotiation state …
Run Code Online (Sandbox Code Playgroud)

security wcf scaling

5
推荐指数
1
解决办法
1830
查看次数