Affichage des articles dont le libellé est Active questions tagged .net - Stack Overflow. Afficher tous les articles
Affichage des articles dont le libellé est Active questions tagged .net - Stack Overflow. Afficher tous les articles

dimanche 28 juin 2015

SignalR or simillar for winforms

I need to know if there is something like SignalR but for Winforms, some nuggets or library for paid, someone who can guide me please.

The beginning of my problem is that I have the need to obtain data automatically when the table is updated.

Thanks.

Parallel.ForEach stops being parallel for the last few items

I have an external singlethreaded program that needs to be run multiple hundred times with different parameters. To make it faster I want to run it once for each core at the same time. To do that I used Parallel.ForEach running on a list with the different parameters to pass to the external program:

var parallelOptions = new ParallelOptions {
    MaxDegreeOfParallelism = Environment.ProcessorCount // 8 for me
};

Parallel.ForEach(ListWithAllTheParams, parallelOptions, DoTheStuff);

...

private void DoTheStuff(ParamType parameter, ParallelLoopState parallelLoopState, long index)
{
    // prepare process parameters etc.
    theProcess.Start();
    theProcess.WaitForExit();
}

Pretty straightforward and works nicely... until the last ~10 items - they don't get parallelized for some reason and just run one after another. I've confirmed this by looking at the cpu usage and the running programs in the Task Manager.

This does not happen when I populate the parameter list with only a few (say, 10) items.

Can somebody explain this behavior to me? Any hints or tips appreciated!

Accuracy of the decimal number type versus the double type in .Net

Consider the following code:

    Dim doubleResult = (21 / 88) * 11
    Dim decimalResult = Decimal.Divide(21, 88) * 11

The doubleResult is 2.625, as it should.

The decimalResult is 2.6249999999999996, so when rounding this to two decimal places will give an incorrect result.

When I change the assignment to:

    Dim decimalResult = Decimal.Divide(21 * 11, 88) 

The result is 2.625!

We adopted the decimal type in our application hoping that it would give us increased accuracy. However, it seems that the decimal type just gives slightly incorrect results on other calculations than the double type does, due to the the fact that it is ten based, rather than two based.

So, how do we have to deal with this idiosyncrasies to avoid rounding errors as above?

Keeping graphics unaltered when TabPage changes

I have a form that displays a set of graphics using a Paint event on a Panel that is docked inside a particular TabPage of a TabControl.

The problem is the following:

When the user switches to a different TabPage and then decides to go back to the TabPage where the graphics were originally displayed, those graphics are invalidated by default so the Panel appears blank.

I would like those graphics to stay unaltered and totally independent from the user's action when switching between different TabPages.

One Requirement:

Since the graphics are complex and take some time to be drawn by the computer, I don't want to repaint the graphics each time by calling the Paint event repeatedly. Instead, I only need to avoid the default invalidation of the graphics.

I have read this other question which may be helpful to solve my problem but it goes beyond my knowledge.

ODBC vs JDBC in social network mobile app?

I want to create an social network app. I use odbc connection in mvc web services to connect database.

I want to know in the future if many users use my app ODBC is enough for many connections or should I use JDBC connection ?

thanks in advance

After deploying site created with last version of Umbraco on iss the css and images are broken

enter image description here

I have made all the usual steps for deploy on iss. The IUSRS -NetworkService has full rights on the web project

Suitable Control for displaying various game levels in a WP8 App

There is a mobile game on which I am working. It has various difficulty sections and each section has numerous levels, 250 levels in each section precisely.

Now, I need a suitable control which can display all the levels and by tapping on a certain level's button/icon, the user is able to move on and play that level.

I tried using a simple ScrollViewer, but that is way too much scrolling for the user even if I display 10 levels in a single row.

So, is there any inbuilt/existing control in WP that I can use to solve my problem?

P.S. Do remember, there are more than 250 levels that need to be displayed.

Many thanks in advance. Cheers!

Add the Text Form Field to the MS Office Word Document

Does anybody know how can I insert the Text Form Field to the MS Office Word 2003 Document (.doc)? And I also want to set the read-only property fo this field. How can I do this with C#?

How to do a SQL Server DB schema update with zero downtime

What do you think is the best way of updating an existing SQL Server (we are using SQL Server 2014, but could update to 2016) database schema (incl its data) with zero downtime of the overall system, i.e. applications using the database?

The business requirements is to have a zero downtime of all the applications and services using the database. We could say we only do backwards and forward compatible database schema changes, e.g. adding columns, but not removing existing columns.

Of course the business would like to have a backup before we do the database change, in case something goes really wrong and we need to rollback.

The system is transactions heavy, meaning potentially thousands of transactions per second.

The applications are .net applications, where most of them run in an IIS execution container at the moment (maybe we switch to some other form like self-hosted service etc.) and exopsing their functionality through Web Services.

What would be your approach?

unit test to check uniqueness of million generated strings

I would like to write a unit test to

1) go through a list of 1 million unique random generated strings.

2) Ensure that each numer is 100% unique and there are no duplicates.

What is the best way to check and compare that there are no duplicates.

I have a List<List<int>> set of data, with string representation like this (to give the idea!):

 {{1,3},{-1,-3},{2,5},{-2,-5},{-3,4},{-5,4},{3,5,-4},{6,-8},{7,-8},{-6,-7,8},{7,9},{-7,-9},{3,8,-10},{-3,-8,-10},{-3,8,10},{3,-8,10},{4,9,-11},{-4,-9,-11},{-4,9,11},{4,-9,11},{10,11},{-1,6},{1,-6},{-2,7},{2,-7}}

I want to check if ,in all present numbers, exist a number or set of numbers which only are in positive form. I mean if in the whole data, there is 3 and -3 I should return false, otherwise I have to add 3 as a number which only is present as positive 3, in to another list. (Same thing for only negated number)

Here is how I am trying to do it:

First, generate a unique set of numbers and remove negatives:

private void GenerateCurrentExistingVariables()
{
    _uid = new List<int>();
    var all = _cnf.Data.SelectMany(list => list).ToList();
    _uid = all.Distinct().ToList(); //make list unique
    _uid.Sort(); //sort numbers
    _uid.Reverse(); //reverse so highest numbers would evalaute first!
    _uid = _uid.Where(i => i >= 0).ToList(); //remove negative numbers
}

Then I do something like this:

in a method, I call the code below:

    for (var i = 0; i < _uid.Count; i++)
    {
        if (ExistOnlyInNegatedForm(_uid[i]))
        {
            onlyNegatedList.Add(_uid[i]);
        }

        //perhaps continue

        if (ExistOnlyInPositiveForm(_uid[i]))
        {

            onlyPositiveList.Add(_uid[i]);
        }
    }

Which in turns calls the methods below:

private bool ExistOnlyInPositiveForm(int id)
{
    for (var i = 0; i < _cnf.Data.Count; i++)
    {
        for (var j = 0; j < _cnf.Data[i].Count; j++)
        {
            if (_cnf.Data[i][j] == id)
            {
                return false;
            }
        }
    }

    return true;
}

private bool ExistOnlyInNegatedForm(int id)
{
    var toCheck = -id;
    for (var i = 0; i < _cnf.Data.Count; i++)
    {
        for (var j = 0; j < _cnf.Data[i].Count; j++)
        {
            if (_cnf.Data[i][j] == -toCheck)
            {
                return false;
            }
        }
    }

    return true;
}

This is too much code for this simple task and I feel that this is getting slower and slower when data grows larger...please let me know how can I improve this. Also I would like this to be done using LINQ at least for the sake of less lines of code!

I would love to see a C++ solution as well, so I am tagging c++ in my question (not doing language spam!)

How can i convert and compress in real time batch of images to mp4 video file?

In my directory on the hard disk i have many images: screenshot000001.bmp , screenshot000002.bmp....screenshot001200.bmp

I want to do two things:

  1. For testing using the CMD and to compress and convert the images to mp4 video file.

  2. In my program in real time while my program take the screenshots and save them to the hard disk to compress them and build the mp4 video file in real time.

For the first part i tried to type in cmd :

ffmpeg -f image2 -i screenshot%d.bmp -vcodec libx264 -b 800k video.avi

But what i got is two errors:

[image2 @ 0000000004766380] Could find no file with path 'screenshot%d.bmp' and index in the range 0-4 screenshot%d.bmp: No such file or directory

I copied the ffmpeg.exe to the directory where the images are in. E:\screenshots

For the second part this how i'm taking the screenshots in real time:

A button click event that start a timer:

private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }

Then in the tick event:

    ScreenShot shot = new ScreenShot();
    public static int counter = 0;
    private void timer1_Tick(object sender, EventArgs e)
    {
        counter++;
        shot.GetScreenShot(@"e:\screenshots\", "screenshot");
        if (counter == 1200)
        {
            timer1.Stop();
        }
    }

This line shot.GetScreenShot(@"e:\screenshots\", "screenshot"); save the screenshots to the hard disk. Here after each screenshot save i want to compress and build the mp4 video file in real time.

Showing widget demo in mobile view

I am creating a intranet application to my company which contains different plugins developed by us or commonly used plugins. It is a responsive design. Now I have a new requirement to show the widget demos in different mobile devices like iphone, android etc.

My lead show me this example http://ift.tt/1GUdTos

Based on the device selection we need to show plugins in different devices. For example I have a widget named datatable, I need to enable different views for this. How can i achieve it. I dont have any idea how to implement it. Please help

TeamCity + ASP.NET Webapp: Error about unclosed string literal?

I have a solution where all projects are targeting .NET v4.5.1.

TeamCity (v9.0.4) previously has built the solution just fine.

Added an Asp.Net web application (MVC + WebAPI) to the solution, still targeted at .NET 4.5.1.

It Works on My Machinetm, but TeamCity now fails the build with the following MSBuild error:

[src\app\Web\Web.csproj] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets(186, 67): error MSB4025: The project file could not be loaded. There is an unclosed literal string. Line 186, position 67.

Those might be the line numbers in the targets file that threw the error, because in my file all I see is a </ProjectReference> (which corresponds correctly to two project references that are there.

Any idea what could be causing this?

Insert and Delete error Gridview ASP.NET

I am using SQL command to insert and delete into the grid but getting errors in implementation. How can I write the syntax This is the HTML code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>
<html xmlns="http://ift.tt/lH0Osb">
    <head id="Head1" runat="server">
        <title> </title>
    </head>





<body>

    <form id="form1" runat="server">
        <div>
            <asp:Label ID="label" runat="server">New Task</asp:Label>
            <asp:TextBox ID="textbox1" runat="server" placeHolder="Type  
            new task summary here, and click add" Width="353px">    
            </asp:TextBox>
            <asp:Button ID="button1" runat="server" OnClick="click_add" 
            Text="Add" style="margin-left: 54px" Width="67px" />
            <br />
        </div>

        <asp:GridView ID="grdStatus" runat="server" 
        OnRowCommand="grdStatus_RowCommand" AutoGenerateColumns="false">
        <Columns> 
            <asp:TemplateField HeaderText="Done?">
                <ItemTemplate>
                    <asp:CheckBox ID="checkbx" runat="server" 
                    Checked='<%#Eval("Done") %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ID">
                <ItemTemplate>
                    <asp:Label ID="label12" runat="server" 
                    Checked='<%#Container.DataItemIndex+1 %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Summary">
                <ItemTemplate> 
                    <asp:Label ID="label3" runat="server" 
                    Checked='<%#Eval("Summary") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Created On">
                <ItemTemplate>
                    <asp:Label ID="label4" runat="server" 
                    Checked='<%#Eval("Date")%>' ></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:ImageButton ID="dltButton" runat="server" 
                    ImageUrl="~/images/delete.png"   
                    CommandName="DeleteTask" Text="Delete" Width="30px" 
                    Height="30px" CommandArgument="<%#     
                    Container.DataItemIndex%>" />
                </ItemTemplate>
            </asp:TemplateField>

        </Columns>
        </asp:GridView>


    </form>
</body>
</html>

The c# code is this using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Web.Configuration; using System.Data.SqlClient;

public partial class _Default : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string connectionString =    
WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
        string selectSQL = "SELECT * FROM Table";
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand(selectSQL, con);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();

            adapter.Fill(ds, "Table");

            grdStatus.DataSource = ds;
            grdStatus.DataBind();
        }
    }
    protected void click_add(object sender, EventArgs e)
    {

            string connectionString =   
  WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("INSERT INTO 
            Table(ID,Summary,Created) values ('" + checkbx.Text + "'" + 
            Convert.ToInt32(cmd.Parameters["label2"].Value.ToString()) + 
            "'" + label3.Text + "'" + label4.Text + "'", con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();


    }

    protected void grdStatus_RowCommand(object sender, EventArgs e)
    {
        if(e.CommandName == "DeleteTask")
        {
            string connectionString =    
WebConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
            SqlConnection con = new SqlConnection(connectionString);
            con.Open();
            string query = "delete from Table where id=" + 
            e.CommandArgument + "'";
            SqlCommand cmd = new SqlCommand(query, con);
            cmd.ExecuteNonQuery();
            con.Close();
            fillgrid();
        }
   }

}

VB.Net Code Formatter Like perltidy for perl

Good day!

Are there any code formatter for vb.net that can automate code formatting? like perl's perltidy.

I know I can do it manually but the class that I'm working on is getting bigger and I need a constant formatting for all.

Thank you!

Applying dynamically built expression on collection throws exception

I have the following class:

public class Order
{
    public string Code { get; set; } 
}

And I have built dynamically an Expression, which looks like this:

enter image description here

and I'm building an extension method which looks like:

enter image description here

I have a list of orders which, List<Order> of the expression type and when I apply the filter like this:

var buildExpressionFilter = dynamically constructed Expression here
var orders = GetOrders();
var result = orders.Where(buildExpressionFilter).ToList();

I get the following error: enter image description here

Is obviously that buildExpressionFilter is not properly constructed but I cannot figure out what is the issue.

Does anyone have an idea on how to fix this issue? What may be wrong with my buildExpressionFilter?

Calling a VST plugin with VST.net in Unity3D. Is it possible?

I dont have any experience with VST. Just started researching.

I need to call the member function VSTPluginMain from my VST dll to do some custom audio processing in my Unity 5 project. For a VST host, I added VST.NET 1.0 CLR2 X64 Release dlls in my project. I've read Unity supports only Common Language Runtime 2.

The documentation for VST.net is not working (a blank .chm file and the online version is incomplete). I wasn't able to find any useful samples in the VST.net project templates. Also, does Unity support VST? (the Unity forums are silent about this matter)

Any help is greatly appreciated.

Thank you

Self-hosting ASP.NET 5 within .NET 4.5 Application (without DNX and IIS)

Is it possible to add an ASP.NET 5 Web Application as a reference to a traditional .NET 4.5 project (Windows Service or Console App) and start it in-process?

Ideally within one solution, so that ASP.NET application and host service can share references to other projects in the same solution.

Tried so far:

dnu publish produces packages, but attempting to add them produces following error: Install-Package : Could not install package 'WebApplication1 1.0.0'. You are trying to install this package into a project that targets '.NETFramework, Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. When changing framework dnx451 to net451, Web Application doesn't compile because of missing ASP references.

dnu build produces binaries, but how to run the application? (where to get IApplicationBuilder and IHostingEnvironment instances?)

C# searching and getting Absolute Path of Software

I am new to C# and I want to create a little Autorun Manager in a Console Application. To do that I want to read from the console a keyword like "Steam" and my programm should search on "C:\" and in all subdirectories for a folder called like my keyword but as I say I have no Idea how I can search in all subdirectories.

Thats a little code sample with steam how I would write in registry

//filePath would be the Path of the .EXE file that was found    
string filePath = "\"C:\\Programme\\Steam\\Steam.exe\""; 
string autostartPath = @"Software\Microsoft\Windows\CurrentVersion\Run\";
RegistryKey autostart = Registry.CurrentUser.OpenSubKey(autostartPath, true);
autostart.SetValue("Steam", filePath);

If someone know how to search in all subdirectories and find the correct .exe file.

I would be really grateful for a code sample.

Thanks in advance