.net-4.5

ServiceHost fail to Open() again with new ServiceHost instance when it failed for the first time in WCF self-host

天大地大妈咪最大 提交于 2019-12-12 05:16:16
问题 My symptom is exactly as this post described http://social.msdn.microsoft.com/Forums/vstudio/en-US/302ca96e-a810-4958-9905-90ba1175765d/servicehost-does-not-detech-endpoints-cant-recover-from-a-faulted-state I wonder if this is a known bug. My code is slightly different from Dave's whereas his ServiceHost instance (named WebService) is outside of Start() method. My ServiceHost instance (named host) is declared inside. When debugging, I check in Host Description that the address of endpoints

Changing color of a single cell in WPF Datagrid

六月ゝ 毕业季﹏ 提交于 2019-12-12 04:53:18
问题 I have a WPF Datagrid with variable number of columns and populated at runtime with a 2D array of String[][]. String[] data = .....; datagrid.ItemsSource = data; I need to chance cell colors based on its values. But these values are defined by the user during execution. Most examples I found about changing cell colors use Triggers on the XAML and the value is known in design time. So I'm changing the background of the cell like this: DataGridCell cell = DataGridUtils.GetCell(datagrid, i, j);

Check if an uppercase Letter is inside a string

帅比萌擦擦* 提交于 2019-12-12 04:02:40
问题 I am currently learning C# and RegEx . I am working on a small wordcrawler. I get a big list of many words where I escape those which don't fit to my RegEx. Here's my code: var WordRegex = new Regex("^[a-zA-Z]{4,}$", RegexOptions.Compiled | RegexOptions.CultureInvariant); var secondRegex = new Regex("([A-Z]{1})"); var words = new List<string>(); var finalList = new List<string>(); foreach (var word in words) { if (WordRegex.IsMatch(word) && secondRegex.Matches(word).Count == 1 || secondRegex

Create sub folders in My Pictures from Windows Store application

有些话、适合烂在心里 提交于 2019-12-12 03:46:01
问题 I'm trying to create a folder structure within My Pictures folder from a Windows store app. But I can't seem to get pass the first level. I create my first level folder using the following code: IAsyncOperation<StorageFolder> appFolder = Windows.Storage.KnownFolders.PicturesLibrary.GetFolderAsync("AppPhotos"); if (appFolder==null) { //Create folder appFolder = Windows.Storage.KnownFolders.PicturesLibrary.CreateFolderAsync("AppPhotos"); } Now I want to create another folder below this call

Why does this code not update the database table?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 03:38:37
问题 In a legacy ASP.NET Webforms app, I need to update a database table when the user clicks a button, depending on which checkboxes on the form are checked, using the value from a corresponding label to make the update. It's not working; however, almost-identical code in a Winforms "test" app does work. The FormLoad (Winforms) and Page_Load (Webforms) code works fine; there is no need to show all of that code; they both populate the form/page with pairs of label/checkbox controls. To show how

How to abort a list of tasks from the outside

匆匆过客 提交于 2019-12-12 03:04:46
问题 I am still fairly new to the threading model in .net 4.5 (or threading in general for that matter). I am trying to build a set of abstract classes in order to implement a framework for multithreading a series similar tasks. The rules are that the first line of the input tells how many problems are in the set, and the following lines contain the input for each problem. How many lines of input make up a set can vary from one task to the next, but are normally consistent for a given type of

Task return types gone wrong - “x has the wrong return type”

自古美人都是妖i 提交于 2019-12-12 01:36:51
问题 I have a line of code, that: bool stop = await Task<bool>.Factory.StartNew(Listen, (TcpClient) client); And the corresponding task: public static async Task<bool> Listen(object state) { TcpClient client = (TcpClient) state; NetworkStream connectionStream = client.GetStream(); IPEndPoint endPoint = client.Client.RemoteEndPoint as IPEndPoint; byte[] buffer = new byte[4096]; Encoding encoding = Encoding.UTF8; Random randomizer = null; // Are we still listening? bool listening = true; // Stop the

Resize images with MVC 6 on Ubuntu running ASP.NET 5 on Mono

心已入冬 提交于 2019-12-12 01:36:05
问题 How can I re-size an image in ASP.NET 5, MVC 6, DNX451, with MONO, running on Ubuntu? I have been unable to work this out, as the standard components that I have used such as ImageProcessor and ImageResizer.NET seem not to be working. 回答1: check out this cross platform library: https://github.com/JimBobSquarePants/ImageSharp sample usage: using (FileStream stream = File.OpenRead("foo.jpg")) using (FileStream output = File.OpenWrite("bar.jpg")) { Image image = new Image(stream); image.Resize

Can not use await inside a Parallel.Foreach . error :- The 'await' operator can only be used within an async lambda expression

泄露秘密 提交于 2019-12-12 00:44:03
问题 I have the following method inside my asp.net mvc-5 web application :- public async Task <List<Details>> Get() { Parallel.ForEach(resourcesinfo.operation.Details,new ParallelOptions { MaxDegreeOfParallelism = 20 }, (c) => { ResourceAccountListInfo resourceAccountListInfo = new ResourceAccountListInfo(); using (WebClient wc = new WebClient()) { string url = currentURL + "resources/" + c.RESOURCEID + "/accounts?AUTHTOKEN=" + pmtoken; string tempurl = url.Trim(); var json = await wc

HTTP Error 403.0 - ModSecurity. Action You do not have permission to view this directory or page

北慕城南 提交于 2019-12-12 00:43:40
问题 I have an ASP.NET Website and hosted on shared hosting and everything is working fine but recently I had requirement to call one page of website from php script via cURL but while executing php script via php-cgi.exe I am getting below error; HTTP Error 403.0 - ModSecurity Action You do not have permission to view this directory or page. Note I am able to browse that page from my browser without login to website. What can be the possible cause for this error and could someone guide me to