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
Humphrey Appleby
Oct 30, 2013

Knowledge only means complicity in guilt; ignorance has a certain dignity.

Funking Giblet posted:

Why not write the commit id of the build to the assembly as the Product Number or something, instead of committing from Jenkins.

Thanks, that or similar is what I am thinking of doing.

Adbot
ADBOT LOVES YOU

Mellow_
Sep 13, 2010

:frog:

Uziel posted:

Bah, intellisense has entirely broken for Visual Studio 2013. Has this happened to anyone before? I've tried closing visual studio, restarting, deleting the suo file, etc. Any ideas?

Edit: It was Tools -> Text Editor -> C# -> Auto List Members and Parameter information. Bah. I swear it was checked before.

As an aside, these options tend to get turned off on a Reshaper uninstall or trial expiry.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
Not sure about Mercurial but I've seen setups that the CI server will create a git tag on the commit it used to achieve the same effect.

edit: for background tasks on a web app I've heard good things about http://hangfire.io

Destroyenator fucked around with this message at 02:28 on Jun 2, 2015

wilderthanmild
Jun 21, 2010

Posting shit




Grimey Drawer
So I noticed that System.Diagnostics.Process.Start returns a process object. I also noticed that object implements IDisposable. Does this mean that I always have to dispose the result of Process.Start?

Do I need to write some kind of method like this?
code:
public static void Start(string Path, string Args = "")
{
     System.Diagnostics.Process TheProcess = Args != "" ? System.Diagnostics.Process.Start(Path, Args) : System.Diagnostics.Process.Start(Path) ;
     if(TheProcess != null) TheProcess.Dispose();
}
Or am I okay just calling this?

code:
System.Diagnostics.Process.Start("SomePath");

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

wilderthanmild posted:

So I noticed that System.Diagnostics.Process.Start returns a process object. I also noticed that object implements IDisposable. Does this mean that I always have to dispose the result of Process.Start?

Do I need to write some kind of method like this?
code:
public static void Start(string Path, string Args = "")
{
     System.Diagnostics.Process TheProcess = Args != "" ? System.Diagnostics.Process.Start(Path, Args) : System.Diagnostics.Process.Start(Path) ;
     if(TheProcess != null) TheProcess.Dispose();
}
Or am I okay just calling this?

code:
System.Diagnostics.Process.Start("SomePath");

I don't think you have to dispose it, but the general idea for anything that implements IDisposable is to wrap it in a using block so it's automatically disposed when it goes out of scope.

http://stackoverflow.com/questions/5857893/use-of-process-with-using-block

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
The process object is wrapping a handle so you could argue that it's beneficial to dispose, but that's fairly lightweight and it gets disposed on garbage collection. I've never disposed processes, but when in doubt you're probably better to err on the side of disposing.

wilderthanmild
Jun 21, 2010

Posting shit




Grimey Drawer
Thanks for answering my question.

Ithaqua posted:

I don't think you have to dispose it, but the general idea for anything that implements IDisposable is to wrap it in a using block so it's automatically disposed when it goes out of scope.

http://stackoverflow.com/questions/5857893/use-of-process-with-using-block

I generally do, but I was checking that everything was being disposed properly in my program and noticed that process implements IDisposable. I was a little surprised and worried because I use Process.Start frequently to start applications and open files. I don't tend to do anything with it afterward, so the using statement with a {} afterward looked a little strange to me.

Bognar posted:

The process object is wrapping a handle so you could argue that it's beneficial to dispose, but that's fairly lightweight and it gets disposed on garbage collection. I've never disposed processes, but when in doubt you're probably better to err on the side of disposing.

That's kind of what I was figuring. As long as it doesn't hurt to dispose, better safe than sorry.

ljw1004
Jan 18, 2005

rum

wilderthanmild posted:

That's kind of what I was figuring. As long as it doesn't hurt to dispose, better safe than sorry.

I'm pretty sure it doesn't hurt. Disposing it doesn't abort the process. All it does is surrender your ability to monitor/control the process. I always dispose mine.

chippy
Aug 16, 2006

OK I DON'T GET IT
Got a loving weird problem. As soon as I try and instantiate an SqlConnection, my application immediately exits, with nothing caught in my catch block. I'm literally just doing this in a simple C# console application:

code:
SqlConnection connection = new SqlConnection();
This was originally a using statement with the correct connection string but I've reduced it to this to try and work out what the problem is. Stepping through, it bails out as soon as it executes this line. Originally I had this in a Windows Service but I've moved it in a console app for easy debugging.

Any idea, anyone?

e: Saw someone on Stack Overflow with this problem, a using block fixed it for them (it doesn't for me). I also saw some people suggesting that his .NET installation was broken, but I have other projects that this is working fine in.

chippy fucked around with this message at 17:42 on Jun 3, 2015

raminasi
Jan 25, 2005

a last drink with no ice
Have you double-checked that your debugger is set up to break on all thrown exceptions?

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug
Also check the Event Viewer. The .NET framework will put in an entry, it's usually not very helpful but it's a start

EDIT: Can you also post a little more code? At least what your catch block looks like. Also, make sure your catch block does something with the caught Exception (even Console.WriteLine). Sometimes I'll have a breakpoint on "useless" code and the JITer realizes this and skips it.

gariig fucked around with this message at 18:01 on Jun 3, 2015

raminasi
Jan 25, 2005

a last drink with no ice
This assert didn't trip (DEBUG is set):
C# code:
System.Diagnostics.Debug.Assert(!Double.IsInfinity(coreMultiplier));

Immediate Window posted:

coreMultiplier
Infinity
Double.IsInfinity(coreMultiplier)
true
!Double.IsInfinity(coreMultiplier)
false


:wtc:

epswing
Nov 4, 2003

Soiled Meat

GrumpyDoctor posted:

Have you double-checked that your debugger is set up to break on all thrown exceptions?

And juuust in case, are you in Debug mode (not Release mode)?

chippy
Aug 16, 2006

OK I DON'T GET IT
No, not in release. The method that uses the connection is actually the callback for a Timer. I found that if I just call the method without using the timer it doesn't have this problem. Anyone know why that would stop it working?

It should be pretty simple. It's just a service that needs to run a stored procedure every few seconds. Maybe my approach is all wrong, I'm not at work now bit I'll post some code tomorrow.

ljw1004
Jan 18, 2005

rum

chippy posted:

No, not in release. The method that uses the connection is actually the callback for a Timer. I found that if I just call the method without using the timer it doesn't have this problem. Anyone know why that would stop it working?

It should be pretty simple. It's just a service that needs to run a stored procedure every few seconds. Maybe my approach is all wrong, I'm not at work now bit I'll post some code tomorrow.

EDIT: I'm sorry, I mixed GrumpDoctor's "no exception happening" with your "doesn't even get into the catch clause which surrounds it". Yours sounds really weird. Maybe it's one of the .net uncatchable exceptions?


https://msdn.microsoft.com/en-us/library/system.timers.timer.elapsed%28v=vs.110%29.aspx

quote:

The Timer component catches and suppresses all exceptions thrown by event handlers for the Elapsed event. This behavior is subject to change in future releases of the .NET Framework.

(Well, the MSDN docs say it is subject to change, but I bet it never will change since that'd be a terrible breaking change.)

ljw1004 fucked around with this message at 01:02 on Jun 4, 2015

gariig
Dec 31, 2004
Beaten into submission by my fiance
Pillbug
I hope Satya is paying you the big bucks

chippy
Aug 16, 2006

OK I DON'T GET IT

ljw1004 posted:

https://msdn.microsoft.com/en-us/library/system.timers.timer.elapsed%28v=vs.110%29.aspx


(Well, the MSDN docs say it is subject to change, but I bet it never will change since that'd be a terrible breaking change.)

Hmm ok, well that solves one mystery, but the question is, why is just instantiating the SqlClient with its default constructor throwing an exception, and why is it not throwing the exception when the same method is run without using the timer?

chippy
Aug 16, 2006

OK I DON'T GET IT
Oh, in fact, that's the wrong Timer class anyway. I'm using System.Threading.Timer

TheBlackVegetable
Oct 29, 2006

chippy posted:

Oh, in fact, that's the wrong Timer class anyway. I'm using System.Threading.Timer

Try wrapping the call in a try catch and see what exception is popping out... exceptions in System.Threading.Timer will crash the program

chippy
Aug 16, 2006

OK I DON'T GET IT

TheBlackVegetable posted:

Try wrapping the call in a try catch and see what exception is popping out... exceptions in System.Threading.Timer will crash the program

It's in a try catch and it's not catching anything at all, that's the confusing thing. It's just jumping out of the method. I've come up with a theory as to why in my sleep now though...

chippy
Aug 16, 2006

OK I DON'T GET IT
Nope, that wasn't right. OK, someone help!

This is the console app version. It's mean to be a service eventually. All it needs to do is open the connection and do some work every 6 seconds.

Program.CS:

code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {   
        static void Main(string[] args)
        {
            Importer importer = new Importer();
            importer.Go();
        } 
    }
}
Importer.cs:

code:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading;
using System.Configuration;
using System.Data;

namespace ConsoleApplication1
{  
    public class Importer
    {
        private Timer workTimer;
        
        public void Go()
        {
            workTimer = new Timer(new TimerCallback(ImportMagnaResults), null, 0, Timeout.Infinite);
        }

        private void ImportMagnaResults(object state)
        {
            Console.WriteLine("Creating connection.");

            // Import stuff here
            try
            {
                SqlConnection connection = new SqlConnection();
                Console.WriteLine("Connection created.");
                SqlCommand command = new SqlCommand("ImportMagnaResults", connection);
                command.CommandType = CommandType.StoredProcedure;
                connection.Open();
                //command.ExecuteNonQuery();
                connection.Close();
                connection.Dispose();
                workTimer.Change(6000, Timeout.Infinite);

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

TheBlackVegetable
Oct 29, 2006

chippy posted:

Nope, that wasn't right. OK, someone help!

This is the console app version. It's mean to be a service eventually. All it needs to do is open the connection and do some work every 6 seconds.

Program.CS:

code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {   
        static void Main(string[] args)
        {
            var wait = new ManualResetEvent(false);
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                wait.Set();
            };
            Importer importer = new Importer();
            importer.Go();
            wait.WaitOne();
        } 
    }
}

You'll need to block before exiting the application - I like to use the CancelKeyPress coupled with a WaitOne - hit Ctrl-C to close the application. This should let you see the sql call execute and any hit any exceptions.

ninjeff
Jan 19, 2004

TheBlackVegetable posted:

You'll need to block before exiting the application - I like to use the CancelKeyPress coupled with a WaitOne - hit Ctrl-C to close the application. This should let you see the sql call execute and any hit any exceptions.

This is probably it, chippy - your program is exiting because you're hitting the end of Main. My guess is that SqlConnection's constructor is the first operation expensive enough to cause a context switch that lets Main complete.

chippy
Aug 16, 2006

OK I DON'T GET IT
Yeah, you guys are right I think. Once I worked out how to attach the debugger, it turned out that the service version was actually crashing for a different reason. Got that all fixed up and it's working all nice. Thanks all.

Pentecoastal Elites
Feb 27, 2007

Ok, I think I'm going crazy.

I wrote a small scheduling program for myself and other teachers in my branch (I work at a small academy). One of the things you can do in the program is define a list of custom holidays that get factored in to the automatic syllabus/homework generation process. A winform displays a calendar, you click some dates, the dates turn bold and get added to the list of the syllabus generator.
Wrote it a few months ago. Worked fine. Distributed the software.

New quarter started on Monday. Since then, people have been calling me telling me that my program now crashes out when trying to select custom holidays. It never did that before, and I haven't issued any new versions yet.
I loaded the release version the other teachers have. It crashes.
I tested my current in-progress revision. It crashes. None of the code in the calendar form has changed. It's one isolated part, here:

code:
        private void MarkAllBold()
        {
            Calendar.BoldedDates = ScheduleBuilder.Holidays.Keys.ToArray();
        }
I'm getting an InvalidOperationException. The innerexception is "null" and the stacktrace just goes to
code:
   at System.Windows.Forms.MonthCalendar.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
https://msdn.microsoft.com/en-us/library/system.windows.forms.monthcalendar.boldeddates%28v=vs.110%29.aspx
I'm doing what it says and literally nothing's changed. It worked the last time, and I've changed nothing. Hand to God.

What is happening :psyduck:

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
This SO post is probably relevant: http://stackoverflow.com/questions/30262731/strange-error-in-monthcalendar-just-started-happening-out-of-nowhere

quote:

After I installed the Windows updates from Tuesday and rebooted my PC, I could replicate the problem easily. It turns out this (6 year old!) code now crashes .NET even though it's been working for years.

quote:

I was filling the BoldedDates property with an array of Dates. That was causing the control to automatically call the UpdateBoldedDates() function and there was the crash. All I did was that I replaced the code by adding bolded date one by one (there is no performance loss). When doing this, the UpdateBoldedDates() function must be called manually

Pentecoastal Elites
Feb 27, 2007

That's really dumb!

Thank you, though.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:
If I have an iterator method like this (simplified example):

code:
public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T item)
{
  if (source == null)
    throw new ArgumentNullException("source");

  foreach(var s in source)
  {
    yield return s;
  }

  yield return item;
}
For the most part this works, except that if source is null, then the exception will be thrown when the result is enumerated over, and not when the method is actually called, as you'd normally expect.

I can fix this by doing something like:

code:
public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T item)
{
  if (source == null)
    throw new ArgumentNullException("source");

  return AppendInternal(source, item);
}

private static IEnumerable<T> AppendInternal<T>(IEnumerable<T> source, T item)
{
  foreach(var s in source)
  {
    yield return s;
  }

  yield return item;
}
Which just seems like a rather ugly thing to do for every iterator I write. Is there a better/cleaner way to get the exceptions to be thrown when the method is called?

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
I don't think there's a better way. That's how the extensions on IEnumerable are written.

http://referencesource.microsoft.com/#System.Core/System/Linq/Enumerable.cs,9463aefcdc7c766f,references

Sedro
Dec 31, 2008
You can sometimes write your extension method in terms of existing methods
C# code:
public static IEnumerable<T> Append<T>(this IEnumerable<T> source, T item)
{
    return source.Concat(new[] { item });
}

NihilCredo
Jun 6, 2011

iram omni possibili modo preme:
plus una illa te diffamabit, quam multæ virtutes commendabunt

So if you want to create a WebSharper website, what are your options for good-looking UI controls beside KendoUI?

chippy
Aug 16, 2006

OK I DON'T GET IT
What's the best online resource for learning WPF for someone with prior WinForms experience?

(I think I might have asked this before)

crashdome
Jun 28, 2011
I recommend starting by looking at MVVM Light and viewing one of their projects. Then get a book.

WPF by itself is not entirely too different from WinForms IMO. It's just mostly in XAML instead of a Designer.cs file. As a result, you can fall into the trap of developing using old habits (e.g. tons of Event Handlers, UI references in BL, etc..). You should instead focus on a practice like MVVM because otherwise you'll just make a ton of code-behind to make WPF feel like WinForms which is a bad idea and leads to frustration. I had to cast everything I knew aside about WinForms and practice MVVM a few times to fully understand the capabilities of WPF. I also bought a book about Prism even though I don't use it. The concepts are the same and it's really in-depth.

Sorry if I don't mention a specific book. Most of my knowledge came from Prism 5 for WPF and augmented with blog reading.

edit: Prism 5 for Wpf is free btw

crashdome fucked around with this message at 13:52 on Jun 5, 2015

GoodCleanFun
Jan 28, 2004

chippy posted:

What's the best online resource for learning WPF for someone with prior WinForms experience?

(I think I might have asked this before)

Check out Josh Smith's blog.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

crashdome posted:

WPF by itself is not entirely too different from WinForms IMO.

The basic idea and controls are similar, but the practices are totally different and largely opaque. I like WPF, but I hate that it doesn't help you fall into the pit of success. There's nothing in it that gently guides you into using MVVM and data binding instead of just cramming the entire application in MainWindow.xaml.cs.

chippy
Aug 16, 2006

OK I DON'T GET IT
Yeah, I guess really it's the MVVM pattern I need/want to learn more than anything. Thanks for the recommendations.

re: The recommendations for MVVM light and Prism, would it not be better to just learn the 'pure' WPF framework on its own first? To know how the plumbing works, so to speak. Is MVVM not a fundamental part of WPF anyway?

chippy fucked around with this message at 15:49 on Jun 5, 2015

ljw1004
Jan 18, 2005

rum

crashdome posted:

I recommend starting by looking at MVVM Light and viewing one of their projects. Then get a book.

I found XAML to be really incomprehensible until I read a book on it. The MSDN documentation was just to piecemeal and lacked the bigger picture.

The book I read was "Windows 8.1 Apps with XAML and C# Unleashed" by Adam Nathan. Brilliant book. It looks like he has several others in the series -- "XAML unleashed (Dec 2014)", "WPF 4.5 unleashed (Aug 2013)", "Universal Windows Apps Unleashed (Feb 2015)", "Win10 Apps with XAML and C# unleashed (2nd edition, Dec 2015)". I guess he's milking the cash cow :) I don't know which in the series is best for you.

The big revelation to me was that XAML is merely a general-purpose declarative language for instantiating objects, with XAML language features for wiring them up. Now the kind of objects that people typically instantiate are UI objects from a particular UI framework, either WPF or WinRT. But the XAML language itself is neutral about this.

Adam's book covered both XAML as a language, and (in the book I read) key conceptual things about the WinRT UI framework.


Summary: I think you need to learn XAML as well as MVVM!

GoodCleanFun
Jan 28, 2004

chippy posted:

Yeah, I guess really it's the MVVM pattern I need/want to learn more than anything. Thanks for the recommendations.

re: The recommendations for MVVM light and Prism, would it not be better to just learn the 'pure' WPF framework on its own first? To know how the plumbing works, so to speak. Is MVVM not a fundamental part of WPF anyway?

I find frameworks unnecessary. Grab Josh Smith's RelayCommand and build yourself a base class for your viewModels. You can also learn about implementing IDataErrorInfo from his examples which works hand in hand with wpf/mvvm and provides all input validation needs. See my post here for additional ideas to make things easier for yourself: http://forums.somethingawful.com/sh...0#post442712636

If you have any specific questions I can elaborate on the above.

crashdome
Jun 28, 2011
I might be dragging you in circles with my opinion but, I came from a strictly WinForms background with a little Web Services and ASP.NET sprinkled in. I am looking at my first test project of WPF and it was basically me recreating a WinForms project but, shoehorning it in WPF while trying to comprehend XAML. Once I picked up something on MVVM I realized I barely need XAML other than to fine tune the UI.

If you want to start with XAML and plumbing first, by all means dive away. You will, however, have to understand you really don't need code-behind for most things and the designer still lets you click through and set properties like you are used to. Likewise, XAML will have more advanced topics you'll need for just straight MVVM structure using RelayCommands and some Model binding. I spent most of my time in WinForms writing Databinding and Event Handlers. Most of that goes away if you set up your business logic properly. At least that is my take on it.

Ithaqua posted:

The basic idea and controls are similar, but the practices are totally different and largely opaque. I like WPF, but I hate that it doesn't help you fall into the pit of success. There's nothing in it that gently guides you into using MVVM and data binding instead of just cramming the entire application in MainWindow.xaml.cs.

I guess I meant "the basic controls and ideas" and, as you say, it really doesn't stop you from mimicking WinForm behavior in your design. I would even say it almost entices you to do so if that is what you are most familiar with.

crashdome fucked around with this message at 00:58 on Jun 6, 2015

Adbot
ADBOT LOVES YOU

Captain Capacitor
Jan 21, 2008

The code you say?

NihilCredo posted:

So if you want to create a WebSharper website, what are your options for good-looking UI controls beside KendoUI?

If you ever find out please share it, I'd be interested in what other options are available.

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