Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
After 7 and a half years and over 400 pages, it's time for a new .NET megathread! The old thread is here.

What is .NET?

Wikipedia posted:

[The] .NET Framework ... is a software framework developed by Microsoft that runs primarily on Microsoft Windows. It includes a large class library known as Framework Class Library (FCL) and provides language interoperability (each language can use code written in other languages) across several programming languages. Programs written for .NET Framework execute in a software environment (as contrasted to hardware environment), known as Common Language Runtime (CLR), an application virtual machine that provides services such as security, memory management, and exception handling. FCL and CLR together constitute .NET Framework.

What languages can I use write to fancy-pants .NET applications?
  • C#
  • Visual Basic .NET
  • F#
  • PowerShell
  • IronRuby (alas, this project is pretty dead)
  • IronPython
  • Boo
  • Cobra

What's awesome about .NET languages?
First off, Microsoft is constantly improving the framework and languages -- there's usually a new .NET release every 1-2 years, which brings new versions of C#, VB, F#, etc. Since our last megathread in January 2007, dozens of new features have come along, several of which changed the way we write code on a day-to-day basis. The big ones are:
  • LINQ (.NET 3.5)
  • Lambda expressions
  • Task Parallel Library (TPL) (.NET 4.0)
  • Task Asynchronous Pattern (TAP) aka "async/await" (.NET 4.5)

Plus, Microsoft has created some of the best tooling around. Visual Studio is the IDE that every other IDE wishes it could be, and the .NET framework is huge and has built-in classes and methods to do just about everything.

I want to develop using Visual Studio, but I'm not paying for it!
That's fine, Microsoft has Visual Studio Community for you. Microsoft retired the rather limited "Express" edition of Visual Studio in 2014 in favor of a "Community" edition, which is free to use and full-featured.

Should I be using source control?
Yes!

If you want to stay within the Microsoft stack:

TFS is the all in one ALM solution for the Microsoft world -- it has project planning, source control, automated build, and automated release. It's a solid product, but it requires some forethought when setting it up. The standard source control model is centralized, but it also supports distributed version control by way of native Git support as of TFS2013.

If you don't care about the Microsoft stack:
  • Git is a very popular distributed VCS, but it has a notoriously steep learning curve. It's very, very powerful, though. If you need the kind of flexibility it gives you, it's definitely worth investing the time to learn. VS2012 and 2013 have decent support for basic Git operations built in, but for more complex operations you'll either need to drop to the command line or use a tool like SourceTree or TortiseGit.
  • Mercurial is another distributed VCS, similar to Git but a bit more Windows-friendly. Visual Studio integration exists in the form of VisualHg. TortoiseHg
  • Subversion still works, too! TortoiseSVN
    Visual Studio integration: VisualSvn

Really, the important thing is to use some kind of source control, even for hobbyist projects. It'll save you a lot of pain in the long-run, and possibly even in the short-run. It's entirely possible to switch source control systems if you don't like the one you're using, although the amount of pain in migrating your change history may be prohibitive, depending on where you're going from/to.

I want to make a website. What should I do?
ASP .NET MVC. Don't use ASP .NET WebForms. WebForms was an interesting attempt by Microsoft to make developing web applications closer to developing desktop applications. It didn't really accomplish that, and at this point it really just gets in the way of writing modern, dynamic sites.

I want to make a desktop application. What should I do?
WPF. Make sure you follow the Model-View-ViewModel (MVVM) pattern. Don't use WinForms. The WinForms architecture practically forces you to mix your presentation logic with your business logic, which is never a good thing.

I want to make a "Modern UI"/Metro/Windows Store application!
See above, but also look at Microsoft's Windows Store site.

I want to write a mobile app for iOS or Android!
Xamarin

I want to do some sort of stuff involving a database!
Manually writing queries is for suckers! Use an ORM, but not LINQ to SQL. LINQ to SQL is dying/dead.
Microsoft's replacement is Entity Framework. Personally, I prefer NHibernate, but both are better than LINQ to SQL.

Also,

ShaunO posted:

If you absolutely have to write ad-hoc queries, your queries don't map well to a full-blown ORM, your application is so small can't justify using a full-blown ORM, or you want to query some other IDbConnection provider. Friends don't let friends use DataTables or reinvent the wheel, use dapper.

I want to run my .NET stuff on a non-Windows OS!
Mono is an open-source implementation of the CLR for non-Windows OSes.

Should I be writing unit tests?
Yes! There are some links to a few different unit testing frameworks in this post, but don't worry too much about which one you choose. Writing testable code is harder than writing test code, and the frameworks are all pretty similar to one another.

Books/References
General

Unit Testing
  • The Art of Unit Testing (Osherove)
  • Dependency Injection in .NET (Seeman)

Frameworks/Tools
  • NuGet - Microsoft's package manager. It's built into modern versions of Visual Studio and it makes finding, installing, and configuring third-party libraries a breeze. You can also set up your own NuGet server for distributing internal libraries, if you want!
  • Autofac, an IoC container for .Net. Getting started guide.
  • Automapper. AutoMapper is a neat little tool to help mapping one object to another.
  • Elmah (Error Logging Modules and Handlers), an application-wide error logging facility for ASP.Net. Here's a list of guides and articles.
  • FluentValidation, a validation library that uses a fluent interface and lambda expressions for building validation rules for your business objects.
  • Json.NET, JSON serialization and deserialization
  • NUnit, a different unit testing framework
  • XUnit, yet another unit testing framework
  • SpecFlow, a behavior-driven development tool -- define a domain-specific language, map your language to test actions, then write your tests in plain English! This is great when you're working on a complex system that requires extensive validation from non-developers. A BA can help you write your tests, and then bugs are their fault!
  • Sandcastle/Sandcastle Help File Builder - A toolset that will turn all those documentation comments into actual documentation. Sandcastle generates intermediate files from the comments, and SHFB turns the intermediate files into final outputs that can also include conceptual content (tutorials, overviews, etc.). Multiple targets are supported, and you can use it standalone or with a convenient Visual Studio plugin. It works best with C# and VB.NET, but F# is mostly doable with some tweaking.

Visual Studio Plugins
  • ReSharper - General code inspection/analysis/refactoring. Highly recommended, but not free!
  • GhostDoc - Generates useful XML comments for your methods, you just fill in the blanks. Pretty great if you're working on any sort of public-facing API.

Thanks to Drastic Actions, mortarr, Dust!!!, ShaunO, Dr. Poz, Knyteguy, GrumpyDoctor, and Destroyenator, wwb, and other people I probably forgot to include here for suggestions and links!

New Yorp New Yorp fucked around with this message at 00:08 on Apr 17, 2015

Adbot
ADBOT LOVES YOU

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Update: 11/12/2014: VS2015, C#6/VB14, .NET 2015

ljw1004 posted:

Plug:

We launched "VS2015 Preview" today: download

For .NET, it's going completely open source. The .NET team will do their development (checkins, bugs, ...) all in the open. If for whatever reason you wanted to package up your own tweaked version of System.Xml.dll with your app, say, you'll be able to do that.

For WPF, it has a solid roadmap for the future.

For VB/C#, here are complete lists of all new language features in C#6 and VB14.

Here in the VB/C#/.NET teams we're pretty excited! We'll writing more on the .NET blog, C# blog and VB blog, once we have time to write it in the coming weeks :)



EDIT: Got to mention the new VS2013 Community Edition. It's free, and a major step up from the "express" editions - kind of like the "Pro" version of VS, also allowing VS extensions. It's free for any non-enterprise application development.

New Yorp New Yorp fucked around with this message at 17:50 on Nov 12, 2014

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

crashdome posted:

I've never used Git because gently caress command line. Although, I do find TFS a bit confusing at times. I thought Git would be more confusing. Is that not true? Can I seamlessly browse my projects in VS with Git? Can I type a comment in a textbox and push pending changes to Git? I'm a lone developer with a few read-only accounts to my projects.

If so, I'd try setting up a Git repo just to play with. It's just as easy to set up Git in VS online as it is to use their TFS. I just thought I would be forced to use a command line or third party tools to use it?

I'm not a fan of Git, but every time I talk about why I don't like Git I get dogpiled by people telling me I'm stupid, so I won't get into it. The Git tools in VS2013 are solid. They're not great, but they're usable and getting better with every update. Doesn't hurt to try it... just open up the Team Explorer and add a new repo, and you should be off and running.

If you have any TFS questions, you can PM me or ask here... I know TFS like the back of my hand.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Malcolm XML posted:

async/await introduces just as many issues as it solves imo

What issues does it introduce?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

ATM Machine posted:

Visual Studio question: I'm curious as to whether there is a productivity extension that replicates Sublimes' features like line duplication, control+d selection searching, or multiple editing locations.

What I'm asking for is a Sublime flavoured Visual Studio. After working with Sublime for so long I really miss being about to ctrl+d a variable or string or whatever, then tap an arrow key to start typing after all of them at once. I was a big fan of being able to highlight something then type in a brace of some sort, and it'd put one either side of the selection.

ReSharper does that kind of stuff.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

RICHUNCLEPENNYBAGS posted:

What's wrong with Task.RunSynchronously or even just Result? Well, I mean, what's wrong that some other syntax would fix?

If you have async code and try to use it synchronously, Bad Things can happen in the form of deadlocks; the async code just waits for something that's never going to happen because everything else is held up waiting for the task to complete. Of course it all depends on the synchronization context... a console app will be fine because it has no synchronization context, it just passes it off to the task scheduler.

[edit]

Even though Stephen Cleary irks me on a personal level, he knows this poo poo inside and out and explains it really well:

http://msdn.microsoft.com/en-us/magazine/jj991977.aspx

New Yorp New Yorp fucked around with this message at 07:48 on Jun 21, 2014

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Deus Rex posted:

Let's be clear about what you're saying here - TFS is free up to 5 developers until you have to purchase a support contract from some TFS consultant to figure out how to make it work.

No?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

wwb posted:

As for the OP, there really should be some other SCM options. Here is my rewrite:

Thanks, I'll update the OP tonight. I was focusing on Microsoft tooling because this is the catch-all Microsoft development thread.

Come to think of it, I'll add a build and release section while I'm at it, and a cloud section.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Dietrich posted:

Holy poo poo why does build time on the Hosted Build Controller cost $.05 a minute?

If you're doing true CI, I strongly recommend hooking up an on-prem CI solution. Team Build will of course work just peachy with VSO, as will Jenkins and TeamCity.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

shrughes posted:

Why the gently caress doesn't the OP have a link to the old thread?

I updated the OP with the link, thanks for the perplexingly hostile reminder.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

GrumpyDoctor posted:

Can I thank you for making the great OP and suggest adding Sandcastle/SHFB to it :shobon:

Sure, write up a description and give me links because I'm lazy.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

PapFinn posted:

I'm not sure if this is the place to ask, but I'm working on picking up some job specific skills to make myself more useful with my company. We are using Classic ASP with Visual Basic. My understanding is that this is a significantly different environment that a ASP.Net/VB.Net environment.

Is that an accurate statement? If so, are there any suggested online resources for learning Classic ASP/VB? So far I'm looking at w3schools and http://www.tizag.com but I'm not sure if either of those are my best place to start or if I should just find some old books.

Any current sources for online learning are obviously focusing on modern frameworks, not stuck firmly in the past like my company.

If you're familiar with modern languages and frameworks already, there's nothing much to pick up. It's your standard unmaintainable "presentation and business logic mushed together in one place" mess. Avoid working on it if you can, it sucks and no one hires classic ASP developers anymore.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Newf posted:

More trouble in ASP land. I think that my goal should be obvious from the code, but I'm having a lot of trouble googling the right answers. I'm working with a ListView.

code:
<ItemTemplate>

Length is <%# Eval("States.Length") %>

<%

 int length = int.Parse(Eval("States.Length").ToString()); // error
 
 for (int i=0; i<length; i++)
 {
  Response.Write("<li>");
  Response.Write(Eval("States[" + i + "]")); // again?
  Response.Write("</li>");
 }

%>

</ItemTemplate>
The error that gets thrown here is Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. Presumably the same thing would happen if it reached that line in the loop.

Suggestions?

Use a databound control, as suggested? This should be in a repeater, it looks like.

Or, better yet, don't use webforms if you don't have to.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Bognar posted:

DateTime precision only goes down to the 100 nanoseconds. If you just want to use the built-in formatting DateTime formatting options, then I would say to make a class that wraps DateTime (e.g. PreciseDateTime) to delegate .ToString() calls and use whatever level of precision you need.

It might be worth looking at NodaTime, too. I don't know if it has that level of precision, but since it's maintained by a notorious calendar nerd, I wouldn't be surprised if it does.

[edit]
Actually, nevermind. It doesn't... yet.

https://twitter.com/jonskeet/status/484436917602516994

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Ochowie posted:

Does anyone have any good SignalR resources? Or has anyone used SignalR and can provide some feedback? I'm trying to send messages with different subsets of a dataset to different clients and I'm not seeing any good guides on how to do that. As an example, I'd like to update stock quotes only for stocks in a given clients portfolio rather than just send all stock quotes and have the client decide which ones to display. I'm not sure that SignalR is the right method for this task but I wanted to play around with it and this seemed like a decent learning application to try.

I've only played with SignalR a little bit, but you should be able to create groups, then send messages to just members of that group.

http://www.asp.net/signalr/overview/signalr-20/hubs-api/working-with-groups

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

gently caress them posted:

So I finally felt like playing with LINQ :q:

code:
     
Dim splitDLNList = new List(Of String) From {"harbl","","","","","H012345678901", "H-012-345-67-89-01"}
Dim DLNMask As New Regex("^[a-zA-Z]{1}[0-9]{12,13}$")
		
Dim EnumerableDLNList = splitDLNList.Select(Function(x) x.Replace("-", "")) _
				    .Where(Function(x) DLNMask.IsMatch(x) And (Not String.IsNullOrWhiteSpace(x)))
EnumerableDLNList.Dump()
This works in LINQpad. This does not work right in my application.

Why is the where executing before my select?

It isn't. It works fine in an arbitrary console application. What's this "Dump" extension method?

BTW, the idiomatic way to do this in VB would be with query syntax:

code:
Dim EnumerableDLNList = From x In splitDLNList
                        Let replaced = x.Replace("-", String.Empty)
                        Where DLNMask.IsMatch(replaced) And (Not String.IsNullOrWhiteSpace(replaced))
                        Select replaced

New Yorp New Yorp fucked around with this message at 19:26 on Jul 15, 2014

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

gently caress them posted:

Do you think that the hyphens that I'm taking as input might be different from the hyphens I'm using in the inlined defined list for my linqpad?

Entirely possible. – is a different character from -.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Newf posted:

What method does HashSet<> use in order to determine whether an element is already a member of the set?

I've got a set of bean objects, but I'd like only one field in the bean to be the 'key' for insertion. Eg, I want to prevent the insertion of new objects into the set if it's key is already contained in the set. I has assumed from the name that it was checking hashes as a unique ID, but the following doesn't work:

code:
public class DataBean
{
  public String Key;
  public String OtherData;

  public override int GetHashCode()
  {
    return Key.GetHashCode();
  }

  public DataBean(String k, String D) { Key = k; OtherData = D }
}

var set = new HashSet<DataBean>();
set.Add(new DataBean("1234", "other data"));
set.Add(new DataBean("1234", "hello world")); // set now contains both objects, but the second Add should have failed

So, you want to quickly store and retrieve key-value pairs. Why are you not using a dictionary?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Newf posted:

That had occurred to me, but wouldn't a dictionary's default action be to overwrite the data associated with an existing key with the new data? I want to keep the original. In particular, the only thing that changes with the new inserts is a timestamp, but I'm only interested in knowing the earliest timestamp.

Semantically, it's a set of these objects, and the 'Key' here is itself data, so I don't like splitting the object into Key / Value.

Can you describe the initial problem in a little bit more detail? I'm always wary of the XY Problem rearing its head.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

chippy posted:

Bear in mind that it's also recommended that if you override Equals(), you should also override GetHashCode(), to ensure that in any case where Equals() returns true for a pair of objects, GetHashCode() would return the same hash, and vice versa.

In Java at least, if you don't do this, you can get funky behaviour with Sets and other collections. I'm not 100% sure if this applies to C# too, but I would think it likely.

You're correct.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Bognar posted:

Personally, I'd use a Dictionary and check .ContainsKey before insertion, but I don't think there's a functional difference. It just seems more appropriate to me to use a Dictionary when you're working with keys and values.

I'm with you. And I've seen too many bad GetHashCode overrides.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Ciaphas posted:

I have a List<DataRecord> dataRecords that I want to display in a WPF DataGrid. DataRecord is defined more or less as follows:

C# code:
public class DataRecord
{
   public ulong Yeartime { get; set; }
   public List<DataItem> Items {get; set; }
}

public class DataItem
{
   public MetaData Info {get; set;}
   public object Data {get; set;} // any of IntX, UIntX, single, double, byte[], char[]
   public string DataAsString { get { /* ... */ } }
}

public class MetaData
{
   public string Name {get; set;}
   public DataType Type {get; set;} // enum, not important
   // ...
}
This info is being filled by reading a file, which is where I learn the number of DataItems in a single record and their metadata (and of course the data itself).

Setting my DataGrid's ItemSource to dataRecords does more or less what I expected: give me two columns of Yeartime and Items, the former being the numbers I expect and the latter being "(Collection)".

I want to programmatically break out that List<DataItem> each into their own column, with the header being item.Info.Name and the cell data being item.DataAsString.

How would I go about this? Binding is a confusing and horrifying subject to me, I'm just barely getting started with C# and .NET let alone WPF :ohdear:

You can either define a template column to display the additional stuff, or let part of your viewmodel's behavior be to transform and project the data into a type intended for display.

Option 1:
code:
//SomeRecords is an ObservableCollection<DataRecord>

<DataGrid ItemsSource="{Binding SomeRecords}" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTemplateColumn>
            <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <Grid>
                <TextBlock Text="{Binding Yeartime}"/>
                </Grid>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
        <DataGridTemplateColumn>
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Grid>
                        <DataGrid ItemsSource="{Binding Items}"/>
                    </Grid>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Yeah, the Option #2 I was talking about was more along these lines:

You have your collection of DataRecords. Those obviously aren't intended for display as-is -- it's some sort of DTO. It represents the raw data you got back from something.

You should be, at some point prior to that object hitting your view, transforming it into a model intended for actual display. Automapper can help here, or you can do it by hand. Once you have a nice, simple model of the data that's intended for display, you just bind that to your data grid and you're golden.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

wwb posted:

Ran headlong into a windows thing that someone here might have ran into -- it seems that Visual Studio 2013 installed HyperV with Update 2 because of windows phone. Unfortunately hyperv breaks networking on VirtualBox and I need that function a lot more than I need to be able to emulate windows phone. Anyhow, I didn't figure this out until after I tried to upgrade virtualbox and ended up with a bunch of screweyness in the network stack somewhereas I can't seem to uninstall or reinstall it. Moreover, I can't remove hyperv at all -- I can uncheck the box, it runs the uninstall, reboots and then hangs at about 36% before rolling back my changes. I've looked in a few of the obvious places but I haven't found any rhyme or reason to this, is there some other tree I should bark up? Or has anyone run into this at all -- everything from google seems to be about people having problems installing hyperv not removing it.

Can you uninstall virtualbox entirely?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

gently caress them posted:

Is there any rule of thumb as far as MessageBox.show vs actually throwing up some markup and code-behind if you're doing something in WPF? I'm displaying what amounts to a list of "YO these numbers are invalid or were entered wrong" and would rather avoid mucking with markup whenever possible.

OTOH if it's now idiomatic to do something else besides a modal popup I might as well get busy.

It's your call, really. If you need styling and flexibility, use a WPF control. If you don't, use a regular old messagebox.

One thing to keep in mind: Displaying messageboxes (either framework-provided or custom) is not a viewmodel concern. I usually tackle it by raising an event in my viewmodel, then having the view handle displaying it. The reason is, as always, separation of concerns. If you want to test your viewmodel, you'll can't test it if it's popping up new views or messageboxes. If you raise an event, you can hook something up to the event to simulate results.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

gently caress them posted:

Also since it's, uh, terrible, and huge, and crossposting is something I'd rather not do (unless truly warranted) I'm trying to go through some threaded stuff: the old worker thread and wait window idiom!

Click here for green forum action.

I seriously want to unfuck this. That thread.sleep(100) poo poo makes me feel ashamed and I'm not the one who wrote it.

Is it Winforms?

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

gently caress them posted:

I honestly don't know :smith:

I thought XAML == WPF but googled first. Now I know that is not the case.

Edit: I think.

In WinForms, assuming you just have a stupid form that has a textbox that shows whatever text you set with the "SetText" method:

code:
            var waitForm = new Form2();

            bool longRunningThingComplete = false;
            waitForm.Show();
            try
            {
                while (!longRunningThingComplete)
                {
                    this.DisableWhateverNeedsDisabling();
                    await Task.Delay(1000);
                    waitForm.SetText("Hi");
                    await Task.Delay(1000);
                    waitForm.SetText("I did more work");
                    await Task.Delay(1000);
                    waitForm.SetText("Almost done");
                    await Task.Delay(1000);
                    longRunningThingComplete = true;
                }
            }
            finally
            {
                this.EnableWhateverNeedsEnabling();
                waitForm.Close();
            }        }
This assumes that you'll be able to do whatever work needs doing in an asynchronous manner by awaiting it. The tricky part is making your work asynchronous. If you're not interacting with the UI at all in your long-running work, you could just do a Task.Run() on it and await that.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

gently caress them posted:

I feel like I haven't adequately explained what the real problem is. The XY problem also just left me a voice mail.

It does work IFF something slow and long is going on before it calls .EndWaiting(). If it basically just goes "welp there's nothing to do here" and quickly calls .EndWaiting() it ends up with a null THIS. Also, the wait window never actually pops up, making me think it was never constructed before the worker thread beep-boops along and realizes there's no need to call the longRunningthing.

I could work around this by checking if there's even any reason to call longRunningThing before bothering to fire up the wait window, but I'd rather solve the problem itself entirely.

No, I understand the problem. The root cause is that the approach the code is taking is dumb. Instead of keeping the UI responsive and doing the work on a different thread, it locks the UI thread doing the work and makes its own temporary special snowflake UI thread to report progress.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Scaramouche posted:

This might be an algorithmic question instead of a .NET question, but I'm doing it in VB.NET so I figured I'd ask here.

I've got to 'sanitize' a couple hundred thousand product titles. These titles were constructed by a relatively simple algo created years ago that was basically:
(company name) + (quality) + (title) + (optional dimension) + (optional size)

The problem being, this algo has been applied to several suppliers and manufacturers, and not all of them are consistent. Upon reflection, and uploading products to a new platform, we're seeing some hinky names like (plusses added to show which part is which):
"Butts Corp + 14k Yellow Gold + Yellow Gold Back Scratcher + + 8 inches"

The problem being, some vendors are including the quality in the title, and it's leading to redundancy. I've already figured out how to replace the ones that are exactly the same (e.g. 'Butts Corp Sterling Silver Sterling Silver Butt Plug 5 inch diameter") by doing a relatively simple regex/matchcollection. However, in the example above, the quality ("14k Yellow Gold") is not an exact match with the quality in the title ("Yellow Gold Back Scratcher"). So what I'm wondering, before going down a long road of split and for...next, is there an elegant way to try to match and replace fragments of Quality against Title, deleting on match so I only have 1 Quality and a modified Title? Ideally the result would look like:
"Butts Corp 14k Yellow Gold back Scratcher 8 inches"

You might want to look into NUML (http://numl.net/) for this one. It's pretty neat. Basically, you give it a bunch of examples of clean data, a bunch of examples of unclean data, and then run it against your real dataset and let it sort things into two buckets. You'll still have to clean it up manually, but at least it'll help you identify the items that need human love.

New Yorp New Yorp fucked around with this message at 21:30 on Jul 18, 2014

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Newf posted:

My knowledge of F# has now increased from nothing to "it's like C# except you use two semicolons". I'm confident that this is accurate.

This is entirely inaccurate.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Nevett posted:

Get LINQPad! The free version will let you do this (and almost everything else except intellisense)

Don't let the name fool you, it's great as a general code scratchpad.



Or just use Powershell, which is already installed on every modern version of Windows. Syntax is a bit different, but it's easy to learn:

[System.IO.Path]::GetInvalidFilenameChars()

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Does anyone have any good resources for how to build a modern SPA that leverages MVC5/WebAPI and SignalR and whatever JS frameworks are hot right now? I haven't done any webdev in the past few years, and I really want to put something modern together to keep my skills sharp.

Part of the fun is that I'm absolutely terrible at HTML and CSS. I have to resist the urge to use tables for layout.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Just wanted to thank everyone for the web app advice. I ended up saying "gently caress it" and starting out with just MVC, jQuery, and SignalR. I hacked a tech demo together last night, then spent today redoing it using knockout because the JS was turning into a big mess of random DOM manipulation. I'll probably revisit everything with bootstrap when I have some free time, since the HTML is pretty hideous. Then I can actually start building real functionality!

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
Neat, I'll check out react when I have some time! Knockout is serving my purposes well enough; it's close enough to XAML databinding that it doesn't hurt my brain too much.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

RangerAce posted:

Well, here's how we do it. Not that this is the One True Way, or anything, but maybe it will give you some ideas.

We have a class library with ALL our business logic in it. We set this up way back when we were still using ASMX web services. The ASMX classes contained one line methods that were wrappers around out class library methods. Eventually we replaced the ASMX services with a WCF Service project. EZ PZ. Today, we set up a Web API 2 project. Same thing, the controller actions in the ApiController classes are just wrappers around our class library methods. Get all of your business logic out of the service layer and client layers, so that your controllers are skinny. Fat controllers are kind of a trap, in my book.

That's how I've always done any sort of service, FWIW.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Knyteguy posted:

How do you guys save little reusable blurbs of code to use through various projects? A class library would work with static methods but that seems like a pain to maintain. Does VS have something like this built in?

Code snippets, but a common library makes a lot more sense. Especially if you version it and reference it in dependent projects out of Nuget.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
I fell into a JS framework hole... I threw out knockout and redid my thing in angular. Knockout is more familiar to me as an MVVM user, but Angular is a lot easier.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Essential posted:

I have a data upload process I need to run at a certain point and I need to check every 30 seconds if it's time to upload. Then when I am uploading data I don't want to check again until the process is complete. Once complete I need to start checking every 30 seconds again.

I was under the impression I could use the System.Threading.Timer with a callback method and pass in a Timeout.Infinite parameter and that would stop the timer when it fired, then restart the timer after the upload method, like this:

However, that keeps calling the CheckDataUpload method.

What do you guys typically use in this situation?

This sounds like a case for a separate data-uploading service. You put a message in a queue saying "i need to upload some data". The uploader takes care of business, and when it's done puts a message in a different queue saying "task is done" that your source application will read from.

New Yorp New Yorp fucked around with this message at 17:50 on Aug 9, 2014

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Essential posted:

Thank you for the suggestion Lucian! Is there a similar async thing I can do with the 4.0 framework? We have to support Win XP machines so I cannot get above 4.0 framework :(

Async BCL on NuGet should work assuming you're developing on VS2012 or later.

Adbot
ADBOT LOVES YOU

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Scuzzywuffit posted:

So I'm attempting to track down a memory leak that I believe is related to an event handler, and I have a dumb question that shouldn't be that difficult to Google but apparently is (or maybe I am just bad at it). If I do the following:

code:
Foo.SomeEvent += new EventHandler(Bar.Method);
Is the resulting EventHandler's _target property pointing to Foo or Bar?

Have you run a profiler? Red Gate's profiler (ANTS, I believe) is excellent at hunting this kind of thing down, and there's a free trial.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply