c#-4.0

C# Form of a form is on separate thread

China☆狼群 提交于 2021-02-10 15:51:55
问题 I have strange problem. I have 3 forms. form1, form2, form3. form1 is starting/main form. in form1 I have code: form2 f2 = new form2; f2.ShowDialog(); form2 opens, I can't focus on foorm1, they are both on the same thread. Just what I want. On form2 I have code: form3 f3 = new form3; DialogResult result = f3.ShowDialog(); I run this code and... For some, unknown for me reason this form3 runs on new thread and I can focus on form2. I don't want this to happen. I have no idea why this form3

C# Form of a form is on separate thread

可紊 提交于 2021-02-10 15:50:43
问题 I have strange problem. I have 3 forms. form1, form2, form3. form1 is starting/main form. in form1 I have code: form2 f2 = new form2; f2.ShowDialog(); form2 opens, I can't focus on foorm1, they are both on the same thread. Just what I want. On form2 I have code: form3 f3 = new form3; DialogResult result = f3.ShowDialog(); I run this code and... For some, unknown for me reason this form3 runs on new thread and I can focus on form2. I don't want this to happen. I have no idea why this form3

Getting stackoverflow exception with Parallel for each , is this due to thread saftey?

孤街醉人 提交于 2021-02-10 07:51:39
问题 I have a foreach loop which works Well . But I want to implement TPL , so did the following: Parallel.ForEach(fileList, currentfileItem => { _clientContext.Load(currentfileItem, w => w.File); _clientContext.ExecuteQuery(); if (currentfileItem.File == null) { throw new Exception( String.Format("File information not found for the item {0}", currentfileItem.DisplayName)); } var currentFileName = currentfileItem.File.Name; if (!string.IsNullOrEmpty(docRevVersionId)) { var info = Microsoft

SecurityException error when calling CLR function

早过忘川 提交于 2021-02-08 21:18:38
问题 I have written a simple user defined function in C# that gets the IP address and returns host name against it code is as follows: public partial class UserDefinedFunctions { [Microsoft.SqlServer.Server.SqlFunction] public static SqlString getname(String ipAddress) { System.Data.SqlClient.SqlClientPermission pSql = new SqlClientPermission(System.Security.Permissions.PermissionState.Unrestricted); pSql.Assert(); System.Security.PermissionSet psql1 = new PermissionSet(System.Security.Permissions

SecurityException error when calling CLR function

雨燕双飞 提交于 2021-02-08 21:15:19
问题 I have written a simple user defined function in C# that gets the IP address and returns host name against it code is as follows: public partial class UserDefinedFunctions { [Microsoft.SqlServer.Server.SqlFunction] public static SqlString getname(String ipAddress) { System.Data.SqlClient.SqlClientPermission pSql = new SqlClientPermission(System.Security.Permissions.PermissionState.Unrestricted); pSql.Assert(); System.Security.PermissionSet psql1 = new PermissionSet(System.Security.Permissions

SecurityException error when calling CLR function

痞子三分冷 提交于 2021-02-08 21:09:28
问题 I have written a simple user defined function in C# that gets the IP address and returns host name against it code is as follows: public partial class UserDefinedFunctions { [Microsoft.SqlServer.Server.SqlFunction] public static SqlString getname(String ipAddress) { System.Data.SqlClient.SqlClientPermission pSql = new SqlClientPermission(System.Security.Permissions.PermissionState.Unrestricted); pSql.Assert(); System.Security.PermissionSet psql1 = new PermissionSet(System.Security.Permissions

HP Fortify : ASP.NET Bad Practices: Non-Serializable Object Stored in Session

徘徊边缘 提交于 2021-02-08 15:15:31
问题 The method set_UserActiveEnvironments() in HttpContextHelper.cs stores a non-serializable object as an HttpSessionState attribute on line 47, which can damage application reliability By default, ASP.NET servers store the HttpSessionState object, its attributes and any objects they reference in memory. This model limits active session state to what can be accommodated by the system memory of a single machine. In order to expand capacity beyond these limitations, servers are frequently

HP Fortify : ASP.NET Bad Practices: Non-Serializable Object Stored in Session

旧巷老猫 提交于 2021-02-08 15:14:28
问题 The method set_UserActiveEnvironments() in HttpContextHelper.cs stores a non-serializable object as an HttpSessionState attribute on line 47, which can damage application reliability By default, ASP.NET servers store the HttpSessionState object, its attributes and any objects they reference in memory. This model limits active session state to what can be accommodated by the system memory of a single machine. In order to expand capacity beyond these limitations, servers are frequently

Count the characters individually in a string using c#

亡梦爱人 提交于 2021-02-08 12:17:27
问题 I have a string as follows: string str = "ssmmmjjkkkkrrr" Using C#, I need to display the count of each individual character as follows: s = 2 m = 3 j = 2 k = 4 r = 3 Thanks in advance. 回答1: The simplest way would be to use LINQ: var counted = text.GroupBy(c => c) .Select(g => new { g.Key, Count = g.Count() }); foreach (var result in counted) { Console.WriteLine("{0} = {1}", result.Key, result.Count); } Or even more briefly: foreach (var group in text.GroupBy(c => c)) { Console.WriteLine("{0}

Count the characters individually in a string using c#

落爺英雄遲暮 提交于 2021-02-08 12:15:44
问题 I have a string as follows: string str = "ssmmmjjkkkkrrr" Using C#, I need to display the count of each individual character as follows: s = 2 m = 3 j = 2 k = 4 r = 3 Thanks in advance. 回答1: The simplest way would be to use LINQ: var counted = text.GroupBy(c => c) .Select(g => new { g.Key, Count = g.Count() }); foreach (var result in counted) { Console.WriteLine("{0} = {1}", result.Key, result.Count); } Or even more briefly: foreach (var group in text.GroupBy(c => c)) { Console.WriteLine("{0}