.net

Using Interlocked.CompareExchange with a class

∥☆過路亽.° 提交于 2021-02-16 04:32:44
问题 System.Threading.Interlocked.CompareExchange operator provides atomic (thus thread-safe) C# implementation of the Compare-And-Swap operation. For example int i = 5; Interlocked.CompareExchange(ref i, 10, 5); After this command, the int i would have a value = 10. And also the compare and exchange happens atomically (single operation). When I tried using this with a class instance, the compare fails and the values are not exchanged. public class X { public int y; public X(int val) { y = val; }

Can you use generic forms in C#?

会有一股神秘感。 提交于 2021-02-15 10:18:33
问题 You should be able to create a generic form: public partial class MyGenericForm<T> : Form where T : class { /* form code */ public List<T> TypedList { get; set; } } Is valid C#, and compiles. However the designer won't work and the form will throw a runtime exception if you have any images stating that it cannot find the resource. I think this is because the windows forms designer assumes that the resources will be stored under the simple type's name. 回答1: Yes you can! Here's a blog post I

Can you use generic forms in C#?

偶尔善良 提交于 2021-02-15 10:16:13
问题 You should be able to create a generic form: public partial class MyGenericForm<T> : Form where T : class { /* form code */ public List<T> TypedList { get; set; } } Is valid C#, and compiles. However the designer won't work and the form will throw a runtime exception if you have any images stating that it cannot find the resource. I think this is because the windows forms designer assumes that the resources will be stored under the simple type's name. 回答1: Yes you can! Here's a blog post I

.NET 4.8 TLS 1.3 Issue on Windows 10

核能气质少年 提交于 2021-02-15 07:53:06
问题 A .NET 4.8 application running on Windows 10 (version 10.0.19041) with enabled TLS 1.3 using the registry as per how to enable TLS 1.3 in windows 10 However running the following code: try { System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13; using (var client = new WebClient()) { var img = client.DownloadData("URL of an image - Only TLS 1.3 at client side - removed for privacy purposes"); MemoryStream ms = new MemoryStream(img); Image i = Image.FromStream(ms); i

How to set multiple services from Entity Framework Core on Repository Pattern?

孤街浪徒 提交于 2021-02-15 07:34:59
问题 I am trying to build a structure using repository pattern in entity framework core. I have an generic interface and a service for general operations. They simply do CRUD transactions. My interface: public interface IGeneralService<TEntity> where TEntity : class { void Delete(TEntity entityToDelete); void Delete(object id); IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = ""

How to set multiple services from Entity Framework Core on Repository Pattern?

半世苍凉 提交于 2021-02-15 07:34:16
问题 I am trying to build a structure using repository pattern in entity framework core. I have an generic interface and a service for general operations. They simply do CRUD transactions. My interface: public interface IGeneralService<TEntity> where TEntity : class { void Delete(TEntity entityToDelete); void Delete(object id); IEnumerable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = ""

Change Border Color of NumericUpDown

爷,独闯天下 提交于 2021-02-15 06:52:29
问题 I am very new to C#, and have a question. I have been able to change the border colors of buttons and such by changing their FlatStyle to "Flat". With the NumericUpDown , I can't change the FlatStyle. I would like to still be able to use the up and down arrows, so just using something else to cover the edges will not work. Here is a simplified version of what I'm doing in my code: using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using

Change Border Color of NumericUpDown

泪湿孤枕 提交于 2021-02-15 06:51:45
问题 I am very new to C#, and have a question. I have been able to change the border colors of buttons and such by changing their FlatStyle to "Flat". With the NumericUpDown , I can't change the FlatStyle. I would like to still be able to use the up and down arrows, so just using something else to cover the edges will not work. Here is a simplified version of what I'm doing in my code: using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using

Change Border Color of NumericUpDown

浪子不回头ぞ 提交于 2021-02-15 06:51:36
问题 I am very new to C#, and have a question. I have been able to change the border colors of buttons and such by changing their FlatStyle to "Flat". With the NumericUpDown , I can't change the FlatStyle. I would like to still be able to use the up and down arrows, so just using something else to cover the edges will not work. Here is a simplified version of what I'm doing in my code: using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using

How to download FTP files with automatic resume in case of disconnect

橙三吉。 提交于 2021-02-15 02:20:11
问题 I can download FTP files, but the download code does not have a resume facility and multi part files download. Because there are file larger than 500 MB, I can't download them continuously, because the connection gets closed and it starts download from beginning. I wanted my code a resume facility if it gets disconnected. The code I am using is: public string[] GetFileList() { string[] downloadFiles; StringBuilder result = new StringBuilder(); FtpWebRequest reqFTP; try { reqFTP =