.net

Calling A COM Component From .NET Windows Service

百般思念 提交于 2021-02-04 16:08:43
问题 I have a Windows Service written in .NET C# which calls a COM component. I also have a .NET Windows Forms test app which I was using to test the COM component. It works fine from the test app. However, when I use the same code in the Windows Service nothing happens. The COM components logs everything to file and the fact the log file doesn't get produced hints that the COM component isn't even being called. Why does this work from my test app but not within the windows service? 回答1: Service

How to check if a string starts and ends with specific strings?

Deadly 提交于 2021-02-04 15:54:04
问题 I have a string like: string str = "https://abce/MyTest"; I want to check if the particular string starts with https:// and ends with /MyTest . How can I acheive that? 回答1: This regular expression: ^https://.*/MyTest$ will do what you ask. ^ matches the beginning of the string. https:// will match exactly that. .* will match any number of characters (the * part) of any kind (the . part). If you want to make sure there is at least one character in the middle, use .+ instead. /MyTest matches

How to check if a string starts and ends with specific strings?

让人想犯罪 __ 提交于 2021-02-04 15:52:25
问题 I have a string like: string str = "https://abce/MyTest"; I want to check if the particular string starts with https:// and ends with /MyTest . How can I acheive that? 回答1: This regular expression: ^https://.*/MyTest$ will do what you ask. ^ matches the beginning of the string. https:// will match exactly that. .* will match any number of characters (the * part) of any kind (the . part). If you want to make sure there is at least one character in the middle, use .+ instead. /MyTest matches

dynamic in Task.Run

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-04 15:51:23
问题 I have a long running task with the same name in unrelated classes. I was trying to have this code in common method using dynamic. I am getting following error Microsoft.CSharp.RuntimeBinder.RuntimeBinderException was unhandled by user code Message=Cannot implicitly convert type 'void' to 'object' I tried to isolate the code to the following class Program { static void Main(string[] args) { MainAsync(); Console.ReadKey(); } static async void MainAsync() { var classA = new ClassA(); var classB

Invoke Enumerable.Where (or other overloaded generic method) using reflection

守給你的承諾、 提交于 2021-02-04 15:47:20
问题 There are 2 overloads (or method signatures) of the "Where" method in Enumerable class: namespace System.Linq { public static class Enumerable { public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate); public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Func<TSource, int, bool> predicate); } So var where = typeof(Enumerable).GetMethod("Where") throws an exception stating an ambiguous match because, of

Rotate photo with SkiaSharp

强颜欢笑 提交于 2021-02-04 15:33:42
问题 I'm trying to rotate photo with SkiaSharp to 90 degrees with following code: public SKBitmap Rotate() { var bitmap = SKBitmap.Decode("test.jpg"); using (var surface = new SKCanvas(bitmap)) { surface.RotateDegrees(90, bitmap.Width / 2, bitmap.Height / 2); surface.DrawBitmap(bitmap.Copy(), 0, 0); } return bitmap; } But when I save bitmap to JPEG file, it has margins both on top and bottom of image. Original image: http://imgur.com/pGAuko8. Rotated image: http://imgur.com/bYxpmI7. What am I

Why call GC.KeepAlive in the end, and not in the beginning? [duplicate]

为君一笑 提交于 2021-02-04 15:22:05
问题 This question already has answers here : Understanding garbage collection in .NET (2 answers) Closed 7 years ago . From GC.KeepAlive() on MSDN: Code this method at the end, not the beginning, of the range of instructions where obj must be available. Why does it have such non-intuitive behavior? 回答1: Because otherwise technically the JIT and CLI could determine that the value isn't used after that point, and consider the object viable for collection. Heck, the compiler could decide to remove

How to get the digits before some particular word using regex in c#?

拈花ヽ惹草 提交于 2021-02-04 14:56:55
问题 We will use below regex to get the digits before the words. Example : 838123 someWord 8 someWord 12 someWord (\d+)\s*someWord But sometimes anything will come between Number and word.Please see the below example line. Ex: 43434 of someword 12 anything someword 2323 new someword How to get the exact digit before that word using regex? Please give me your suggestions. 回答1: Do this: (\d+)[^\d]+some[wW]ord You need to accept anything other than digits themselves. Also I considered both w and W

How the assembly version matching works exactly?

早过忘川 提交于 2021-02-04 14:49:45
问题 Let's say I have assemblies in GAC with versions, 1.1.1.5, 1.1.5.1, 1.1.6.2, 1.2.1.1 and 2.1.2.1. My application have a reference of 1.1.3.0 version. Which assembly will be matched at runtime? and what are the actual rules for assembly matching? 回答1: If your reference requires a specific version, by default, it will fail on assembly load, as that version doesn't exist. This can be configured, however, via Assembly Binding Redirection. There are various options of what will happen here,

How the assembly version matching works exactly?

给你一囗甜甜゛ 提交于 2021-02-04 14:48:27
问题 Let's say I have assemblies in GAC with versions, 1.1.1.5, 1.1.5.1, 1.1.6.2, 1.2.1.1 and 2.1.2.1. My application have a reference of 1.1.3.0 version. Which assembly will be matched at runtime? and what are the actual rules for assembly matching? 回答1: If your reference requires a specific version, by default, it will fail on assembly load, as that version doesn't exist. This can be configured, however, via Assembly Binding Redirection. There are various options of what will happen here,