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
Mr Shiny Pants
Nov 12, 2012

RICHUNCLEPENNYBAGS posted:

I guess my problem is I don't really want to spend that much time on UI and I want, you know, the kind of "Bootstrap" of Windows UI development where there are sensible defaults and I don't usually have to mess with it.


haha MS and sane defaults?

Adbot
ADBOT LOVES YOU

Calidus
Oct 31, 2011

Stand back I'm going to try science!
I might be completely insane for even thinking this is possible but here it goes. Could a template in VS take a c# class and create a matching Controller.

I would like to turn this:
code:
	public class foo{
		public string myString(string input){
			//do stuff
			return string
		}
		public int myInt(int input){
			//do stuff
			return int
		}
	}
Into something like this:
code:
	public class fooController :Controller{
		public JsonResult myString(string input){
			var myFoo = (fool)Session["myfoo"];
			return Json(myFoo.myString(input));
		}
		public JsonResult myInt(int input){
			var myFoo = (fool)Session["myfoo"];
			return Json(myFoo.myInt(input));
			
		}
	}

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



RICHUNCLEPENNYBAGS posted:

Is there any option for C# desktop apps that isn't totally painful? I'm half-tempted to go with self-hosted WebAPI + browser for my next project

To be fair, this would be a lot less painful if I were starting fresh instead of adding another UI to a Silverlight LOB monstrosity. I made a mockup of the UI that looked great and everything really quickly and could have connected it to a fairly clean view model without much trouble, but welp.

GoodCleanFun posted:

If you add it to App.xaml it can be used throughout that project. I think that's what you mean by you don't want to define it globally.

Define your sub controls as part of a common wpf project and use it like a library. A bit hacky, but it should work.

Right - there are already global style definitions in the main project and this stuff just doesn't need to be all the way up there.

I can't justify doing something that far outside the established pattern this thing follows, but I'll keep that in mind for later.

Inverness posted:

Having separate design and runtime constructors is also useful if you want to give your view model design data to see how it looks.

I kinda like that idea.

Munkeymon fucked around with this message at 16:35 on Apr 8, 2015

RICHUNCLEPENNYBAGS
Dec 21, 2010

Calidus posted:

I might be completely insane for even thinking this is possible but here it goes. Could a template in VS take a c# class and create a matching Controller.

I would like to turn this:
code:
	public class foo{
		public string myString(string input){
			//do stuff
			return string
		}
		public int myInt(int input){
			//do stuff
			return int
		}
	}
Into something like this:
code:
	public class fooController :Controller{
		public JsonResult myString(string input){
			var myFoo = (fool)Session["myfoo"];
			return Json(myFoo.myString(input));
		}
		public JsonResult myInt(int input){
			var myFoo = (fool)Session["myfoo"];
			return Json(myFoo.myInt(input));
			
		}
	}

I dunno about with Visual Studio but I solved a similar problem by using reflection and a StringBuilder and TagBuilder to build up Angular HTML views and JavaScript services to talk to my WebAPI controllers. So sure, it's possible to do.

xgalaxy
Jan 27, 2004
i write code
What does everyone suggest for good code coverage tool?
Right now I'm looking at NCover, OpenCover, and dotCover

It looks like NCover and OpenCover provide better code coverage reporting vs dotCover. If I could actually use Visual Studio instead of Xamarin Studio (barf) it might swing things in dotCover's favor but as it is that isn't a possibility for me currently.

Any comments about NCover vs OpenCover? Or some other code coverage tool?

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer

xgalaxy posted:

What does everyone suggest for good code coverage tool?
Right now I'm looking at NCover, OpenCover, and dotCover

It looks like NCover and OpenCover provide better code coverage reporting vs dotCover. If I could actually use Visual Studio instead of Xamarin Studio (barf) it might swing things in dotCover's favor but as it is that isn't a possibility for me currently.

Any comments about NCover vs OpenCover? Or some other code coverage tool?
What's your end goal here? Is it going to be a metric you track or do you just want some confidence?

raminasi
Jan 25, 2005

a last drink with no ice

Calidus posted:

I might be completely insane for even thinking this is possible but here it goes. Could a template in VS take a c# class and create a matching Controller.

I would like to turn this:
code:
	public class foo{
		public string myString(string input){
			//do stuff
			return string
		}
		public int myInt(int input){
			//do stuff
			return int
		}
	}
Into something like this:
code:
	public class fooController :Controller{
		public JsonResult myString(string input){
			var myFoo = (fool)Session["myfoo"];
			return Json(myFoo.myString(input));
		}
		public JsonResult myInt(int input){
			var myFoo = (fool)Session["myfoo"];
			return Json(myFoo.myInt(input));
			
		}
	}

Not statically, I don't think. You'll need runtime shenanigans (either with dynamic or reflection).

F# could :eng101:

xgalaxy
Jan 27, 2004
i write code

Destroyenator posted:

What's your end goal here? Is it going to be a metric you track or do you just want some confidence?

Mostly confidence but metrics would be nice to have. Using git-flow model with feature branches in git and it would be nice to 'fail' a feature branch if it doesn't pass some basic filters.

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

xgalaxy posted:

Mostly confidence but metrics would be nice to have. Using git-flow model with feature branches in git and it would be nice to 'fail' a feature branch if it doesn't pass some basic filters.

Code coverage is an awful metric because it tells you practically nothing and is easy to game with worthless tests.

xgalaxy
Jan 27, 2004
i write code

Ithaqua posted:

Code coverage is an awful metric because it tells you practically nothing and is easy to game with worthless tests.

Thats great. I don't care? I wasn't asking for opinions about code coverage. I was asking for advice about good code coverage tools.

Inverness
Feb 4, 2009

Fully configurable personal assistant.
JetBrains makes pretty solid tools in my experience. I've never used their dotCoverage, but I'd try it just because its them.

xgalaxy
Jan 27, 2004
i write code

Inverness posted:

JetBrains makes pretty solid tools in my experience. I've never used their dotCoverage, but I'd try it just because its them.

Unfortunately dotCoverage is a Visual Studio plugin which I can't use at the moment. I need something that works outside of Visual Studio. Preferably something that can be implemented into a build pipeline inside of Jenkins or some other CI server.

Calidus
Oct 31, 2011

Stand back I'm going to try science!

GrumpyDoctor posted:

Not statically, I don't think. You'll need runtime shenanigans (either with dynamic or reflection).

F# could :eng101:

RICHUNCLEPENNYBAGS posted:

I dunno about with Visual Studio but I solved a similar problem by using reflection and a StringBuilder and TagBuilder to build up Angular HTML views and JavaScript services to talk to my WebAPI controllers. So sure, it's possible to do.


Thank you both for the suggestions. I have an ugly winform app, that I have managed to strip out most of the business logic into its own project. I would like to use that business logic to create a single page web app(maybe 3 pages at most) to replace it. I figured wrapping everything in json would a good place to start.

Sedro
Dec 31, 2008

xgalaxy posted:

Unfortunately dotCoverage is a Visual Studio plugin which I can't use at the moment. I need something that works outside of Visual Studio. Preferably something that can be implemented into a build pipeline inside of Jenkins or some other CI server.
TeamCity has a dropdown for dotCover, NCover and PartCover, so use one of those? I don't use code coverage so can't recommend one.

wwb
Aug 17, 2004

Yup -- TeamCity (another JetBrains product) comes with free dotCover support. The other options require getting licenses on the server but dotCover just works.

Note if you've got a lot of code it can add a ton of time to the build -- Lucene.NET would take 2+ hours with coverage versus ~10 minutes without it.

While I agree code coverage can be gamed, especially if you are using it as a stupid management metric, you can still get a ton of value out of knowing what you are testing and where.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION
I'm using AutoMapper in a project and realised that it performs very slowly in debug mode. When I publish the project and run it properly, it performs fine so I'm thinking it could be related to IIS Express or perhaps something internal to AutoMapper. Does anyone have any ideas what could be causing this? Obviously if it works well in production then that's something at least, but testing/debugging it is a real pain because it's awfully slow.

RICHUNCLEPENNYBAGS
Dec 21, 2010
I'm kind of curious how people use Automapper in real projects. I thought I'd try it out and I quickly found that it was just making more work for me and it seemed like unless your view models were like, almost exactly like your domain models, it wouldn't save you time.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Calidus posted:

Thank you both for the suggestions. I have an ugly winform app, that I have managed to strip out most of the business logic into its own project. I would like to use that business logic to create a single page web app(maybe 3 pages at most) to replace it. I figured wrapping everything in json would a good place to start.

Well if you're gonna do that I'd just skip ahead to generating the views personally.

Cryolite
Oct 2, 2006
sodium aluminum fluoride

RICHUNCLEPENNYBAGS posted:

I'm kind of curious how people use Automapper in real projects. I thought I'd try it out and I quickly found that it was just making more work for me and it seemed like unless your view models were like, almost exactly like your domain models, it wouldn't save you time.

I use it extensively at work for a very large project. We use it to map our domain models to DTOs. What you describe is pretty much our situation. The DTOs are very similar to the domain models except missing some properties not mapped from the domain models and with some additional ignored properties on the DTO.

I don't think we've had any material performance problems with it, debug mode or not, though we don't map nearly enough things for this to be a performance bottleneck for us versus other things. Another team in our company has complained about it being slow however so now they just manually map everything. They also had really complex mappings that are annoying to debug for something that should be so simple, so rather than deal with debugging strange AutoMapper issues for something that's slow anyway they decided to do everything by hand. Life is a lot easier now they say.

Destroyenator
Dec 27, 2004

Don't ask me lady, I live in beer
It's also useful for moving data between your objects and generated classes for messaging/remote services/etc. Never bothered looking into performance though.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Cryolite posted:

I use it extensively at work for a very large project. We use it to map our domain models to DTOs. What you describe is pretty much our situation. The DTOs are very similar to the domain models except missing some properties not mapped from the domain models and with some additional ignored properties on the DTO.

I don't think we've had any material performance problems with it, debug mode or not, though we don't map nearly enough things for this to be a performance bottleneck for us versus other things. Another team in our company has complained about it being slow however so now they just manually map everything. They also had really complex mappings that are annoying to debug for something that should be so simple, so rather than deal with debugging strange AutoMapper issues for something that's slow anyway they decided to do everything by hand. Life is a lot easier now they say.

Yeah, alright. Probably not well suited to my work.

I do like how you can have it run a test to assert you remembered to specify a way to map each field but that does not justify typing a billion lambdas out to set one field as equal to another.

putin is a cunt
Apr 5, 2007

BOY DO I SURE ENJOY TRASH. THERE'S NOTHING MORE I LOVE THAN TO SIT DOWN IN FRONT OF THE BIG SCREEN AND EAT A BIIIIG STEAMY BOWL OF SHIT. WARNER BROS CAN COME OVER TO MY HOUSE AND ASSFUCK MY MOM WHILE I WATCH AND I WOULD CERTIFY IT FRESH, NO QUESTION

RICHUNCLEPENNYBAGS posted:

I'm kind of curious how people use Automapper in real projects. I thought I'd try it out and I quickly found that it was just making more work for me and it seemed like unless your view models were like, almost exactly like your domain models, it wouldn't save you time.

I'm similar to Cryolite in how I use it. You're right though it's a lot of extra work and if I had known when I started what I know now, I probably wouldn't have bothered with it.

comedyblissoption
Mar 15, 2006

epalm posted:

The fact that they haven't offered an uncheckable checkbox for this is criminal. I'm literally afraid to Ctrl-V in *.cshtml files because it's SO loving BAD.

Edit: gently caress
I cut-pasted some html w/ some knockout js bindings one time in a .cshtml to clean it up and move things around, and I spent one hour trying to figure out why things bizarrely didn't work anymore. The answer is that the paste operation can destructively modify the html you are pasting and semantically change its meaning. It took me an hour because I didn't expect that to be a possibility.

Funking Giblet
Jun 28, 2004

Jiglightful!

RICHUNCLEPENNYBAGS posted:

I'm kind of curious how people use Automapper in real projects. I thought I'd try it out and I quickly found that it was just making more work for me and it seemed like unless your view models were like, almost exactly like your domain models, it wouldn't save you time.

It does a lot of things which save time beyond basic mapping. You can validate mappings so that if properties change on the domain model, you will know if you missed them in your view. You can also write generic ValueResolvers which allow you to share methods of mapping specific values (such as localized values / currencies which I've found it very useful for). It can be frustrating if all you are doing is mapping two or three properties each time but it's been a life saver for me multiple times.

Inverness
Feb 4, 2009

Fully configurable personal assistant.
I've been looking around for this information but have had no luck.

What is the minimum framework version that can be targeted with C# 6?

xgalaxy
Jan 27, 2004
i write code

Inverness posted:

I've been looking around for this information but have had no luck.

What is the minimum framework version that can be targeted with C# 6?

It depends on what features of C# 6 you want to use. See this:
http://stackoverflow.com/questions/28921701/does-c-sharp-6-0-work-for-net-4-0

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Nother academic question. I've been going through and updating all this old code I've inherited from when we were much smaller. In this case I'm creating and writing a large file, with little changes for each file (saving 4 times). What the first guy did:
code:
'(Generate 'base' file that the others are modified versions of)
Dim strFileBase as string = System.IO.File.ReadAllText("name of base file")
strFileBase = strFileBase.replace("thing1","thing2")
System.IO.File.WriteAllText("name of thing 2 file", strFileBase)
This quickly ran into OutOfMemory problems that I've been tasked to fix. What I did was:
code:
'(Generate 'base' file that the others are modified versions of)
If File.Exists(strFilename) Then 'strFilename is the base file
                Using reader As System.IO.StreamReader = New System.IO.StreamReader(strFilename)
                    Dim fsY As New FileStream("new file name", FileMode.Create)
                    Using writer As New System.IO.StreamWriter(fsY)
                        Dim line As String
                        line = reader.ReadLine
                        writer.WriteLine(line) 'Header
                        If (line IsNot Nothing) Then
                            Do While (Not line Is Nothing)
                                line = reader.ReadLine
                                line = line.Replace("thing1", "thing2")
                                writer.WriteLine(line)
                            Loop
                        End If
                    End Using
                End Using
End If
Is this streamreader/streamwriter thing common, or am I assuming they can co-exist and this will actually improve the situation?

raminasi
Jan 25, 2005

a last drink with no ice
That is the canonical way to solve that problem, yes.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Scaramouche posted:

Is this streamreader/streamwriter thing common, or am I assuming they can co-exist and this will actually improve the situation?

If you need to work with large files or anything that may use a lot of memory (but doesn't have to), then yes streams are the idiomatic way of limiting memory usage.

I have some suggestions on cleaning up your code, though, if you're interested. StreamWriter has a constructor overload that takes a path and defaults to FileMode.Create. The if statement to check if the line is null is redundant since you're already checking that in the while statement. VB doesn't support assignment inside an expression, so you can't do while((line = reader.ReadLine()) != null) like in C#, though you can do something similar. End result would be something like:

Visual Basic .NET code:
If Not File.Exists(strFilename) Then Return
Using reader As System.IO.StreamReader = New System.IO.StreamReader(strFilename)
    Using writer As New System.IO.StreamWriter("new file name")
        Do
            Dim line As String = reader.ReadLine()
            If line Is Nothing Then Exit Do
            writer.WriteLine(line.Replace("thing1", "thing2"))
        Loop
    End Using
End Using

NihilCredo
Jun 6, 2011

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

You can also combine multiple Using variables in a single block, and terminate your loop by checking for .EndOfStream instead of waiting for a null :eng101:

Also, I wouldn't bother checking for file existence. You want to handle I/O exceptions anyway, because file permissions / drive access / network access could drop at any time during the operation, so might as well write the code only once.

Visual Basic .NET code:
Try

	Using reader As New System.IO.StreamReader(strFilename),  
	      writer As New System.IO.StreamWriter("new file name")

		Do Until reader.EndOfStream
			writer.WriteLine(reader.ReadLine().Replace("thing1", "thing2"))
	    Loop
	
	End Using

Catch exception as System.IO.FileNotFoundException
	MsgBox("File not found!")
Catch exception	as System.UnauthorizedAccessException
	MsgBox("Access denied!")
'etc.
Catch exception as Exception
	MsgBox("Error: " & exception.GetType().ToString)
End Try
Unrelated:

I'm trying to learn the ropes of F#, and I don't quite get why I must always put an identifier in discriminated unions.

Basically, it seems to me that this ought to be legal code:

code:
module myModule = 

    type myType = //...

    type myUnion =
        | double
        | string
	| myType
        
    let myFunction (someArgument : myUnion) = 
        match someArgument with
            | double -> printfn "It's a number!"
            | string -> printfn "It's a string!"        
            | myType -> printfn "It's my type!"        
        
    [<EntryPoint>]
    let myMain args = 
        myFunction 100.0
        myFunction "qwerty"
	myFunction (new myType())
        0
but instead I'm forced to assign three unique identifiers to myUnion's sub-types, at which point I can't just call myFunction on a raw double or myType, and instead have to wrap them up with their respective identifiers.

Can anybody help me understand if there's a reason the above code is not allowed?

NihilCredo fucked around with this message at 00:47 on Apr 11, 2015

raminasi
Jan 25, 2005

a last drink with no ice

NihilCredo posted:

Unrelated:

I'm trying to learn the ropes of F#, and I don't quite get why I must always put an identifier in discriminated unions.

Basically, it seems to me that this ought to be legal code:

code:
module myModule = 

    type myType = //...

    type myUnion =
        | double
        | string
	| myType
        
    let myFunction (someArgument : myUnion) = 
        match someArgument with
            | double -> printfn "It's a number!"
            | string -> printfn "It's a string!"        
            | myType -> printfn "It's my type!"        
        
    [<EntryPoint>]
    let myMain args = 
        myFunction 100.0
        myFunction "qwerty"
	myFunction (new myType())
        0
but instead I'm forced to assign three unique identifiers to myUnion's sub-types, at which point I can't just call myFunction on a raw double or myType, and instead have to wrap them up with their respective identifiers.

Can anybody help me understand if there's a reason the above code is not allowed?

So that you can have multiple cases backed by the same type that vary semantically.
code:
type Shape =
    | CircleWithRadius of float
    | SquareWithSideLength of float

RICHUNCLEPENNYBAGS
Dec 21, 2010

Funking Giblet posted:

It does a lot of things which save time beyond basic mapping. You can validate mappings so that if properties change on the domain model, you will know if you missed them in your view. You can also write generic ValueResolvers which allow you to share methods of mapping specific values (such as localized values / currencies which I've found it very useful for). It can be frustrating if all you are doing is mapping two or three properties each time but it's been a life saver for me multiple times.

Yeah, I'm familiar with those and I think they're cool, but they weren't enough to make me feel it was worth it.

Cryolite
Oct 2, 2006
sodium aluminum fluoride

RICHUNCLEPENNYBAGS posted:

Yeah, alright. Probably not well suited to my work.

I do like how you can have it run a test to assert you remembered to specify a way to map each field but that does not justify typing a billion lambdas out to set one field as equal to another.

Are all of your property names different? I think most people rely on the property names being the same and it mapping those by convention. Most of our maps are nothing more than Mapper.CreateMap<Client, ClientDto>(); with maybe a few .ForMember(x => x.SomeAdditionalProperty, opt => opt.Ignore()). We rarely use MapFrom.

TheEffect
Aug 12, 2013
Am I overlooking something or is there not an easy way to put a click-able e-mail address in an RTF text box? Here's a bunch of pieced-together code that I found online when researching the issue. I had to convert most of it to VB from C# and then tweak it along the way. When I run my program I eventually get an out of memory exception at "thread.Start(threadData)".

code:
Public Interface IMarkupConverter
    Function ConvertXamlToHtml(xamlText As String) As String
    Function ConvertHtmlToXaml(htmlText As String) As String
    Function ConvertRtfToHtml(rtfText As String) As String
End Interface

Public Class MarkupConverter
    Implements IMarkupConverter

    Public Function ConvertXamlToHtml(xamlText As String) As String Implements IMarkupConverter.ConvertXamlToHtml
        Return ConvertXamlToHtml(xamlText)
    End Function
    Public Function ConvertHtmlToXaml(htmlText As String) As String Implements IMarkupConverter.ConvertHtmlToXaml
        Return ConvertHtmlToXaml(htmlText)
    End Function
    Public Function ConvertRtfToHtml(rtfText As String) As String Implements IMarkupConverter.ConvertRtfToHtml
        Return ConvertRtfToHtml(rtfText)
    End Function
End Class

Public Class Converter
    Public Shared Function ConvertRtfToHtml(rtfText As String) As String
        Dim thread = New Thread(AddressOf ConvertRtfInSTAThread)
        Dim threadData = New ConvertRtfThreadData With {.RtfText = rtfText}
        thread.SetApartmentState(ApartmentState.STA)
        thread.Start(threadData)
        thread.Join()
        Return threadData.HtmlText
    End Function

    Public Shared Sub ConvertRtfInSTAThread(rtf As Object)
        Dim threadData = TryCast(rtf, ConvertRtfThreadData)
        threadData.HtmlText = ConvertRtfToHtml(threadData.RtfText)
    End Sub

    Private Class ConvertRtfThreadData
        Public Property RtfText() As String
            Get
                Return m_RtfText
            End Get
            Set(value As String)
                m_RtfText = value
            End Set
        End Property
        Private m_RtfText As String
        Public Property HtmlText() As String
            Get
                Return m_HtmlText
            End Get
            Set(value As String)
                m_HtmlText = value
            End Set
        End Property
        Private m_HtmlText As String
    End Class
End Class
And here's where I call it from Application Events on startup-

code:
NetworkFileController.Converter.ConvertRtfToHtml(NetworkFileController.mainForm.appInfoBox.Text)
All I want to be able to do is have my e-mail address click-able in a rich text box. I have a feeling I'm wasting a lot of time over-complicating things.

Edit- Was following the advice located here- http://stackoverflow.com/questions/28864778/sending-email-as-html-from-richtext-box

TheEffect fucked around with this message at 23:56 on Apr 11, 2015

RICHUNCLEPENNYBAGS
Dec 21, 2010

Cryolite posted:

Are all of your property names different? I think most people rely on the property names being the same and it mapping those by convention. Most of our maps are nothing more than Mapper.CreateMap<Client, ClientDto>(); with maybe a few .ForMember(x => x.SomeAdditionalProperty, opt => opt.Ignore()). We rarely use MapFrom.

Sometimes, but more importantly, usually the view model contains data from multiple tables.

ljw1004
Jan 18, 2005

rum

TheEffect posted:

Am I overlooking something or is there not an easy way to put a click-able e-mail address in an RTF text box? Here's a bunch of pieced-together code that I found online when researching the issue. I had to convert most of it to VB from C# and then tweak it along the way. When I run my program I eventually get an out of memory exception at "thread.Start(threadData)".
code:
    Public Shared Sub ConvertRtfInSTAThread(rtf As Object)
        Dim threadData = TryCast(rtf, ConvertRtfThreadData)
        threadData.HtmlText = ConvertRtfToHtml(threadData.RtfText)
    End Sub
Edit- Was following the advice located here- http://stackoverflow.com/questions/28864778/sending-email-as-html-from-richtext-box

I think you copied your code from http://matthewmanela.com/blog/converting-rtf-to-html/ but mistyped. It should be
code:
        threadData.HtmlText = markupConverter.ConvertRtfToHtml(threadData.RtfText)
That said, I don't know what that code is doing nor why. Whenever I wanted a hyperlink in win32, I made basically just made it a TextBlock, set font to blue underline, set its cursor to a Hand, and added a Click hander.

TheEffect
Aug 12, 2013

ljw1004 posted:

That said, I don't know what that code is doing nor why. Whenever I wanted a hyperlink in win32, I made basically just made it a TextBlock, set font to blue underline, set its cursor to a Hand, and added a Click hander.

I like this much better. Thanks@

LiterallyAnything
Jul 11, 2008

by vyelkin
I'm trying to create a pause function so that users can pause an operation. My code is set up something like so:

code:
    Public Function X
        For Each i In x
            If waitBox.Checked Then
                Wait()
            Else
                DoStuff()
            End If
        Loop
    Return Nothing
    End Function

    Public Function Wait()
        LogOutput("Application paused.")
        Do Until waitBox.Checked = False
            Task.Delay(1000)
        Loop
        LogOutput("Application unpaused.")
        Return Nothing
    End Function
This is probably obvious to most of you but it seems the issue with the above is that the GUI is entirely locked down when the DoStuff() code is running, and so the pause checkbox really doesn't do anything at all until the process is finished running, which defeats the purpose entirely.

I read something about making my application events separate from my GUI, but I'm not sure where to even start with that. Do I add a new module or something?

LiterallyAnything fucked around with this message at 15:42 on Apr 13, 2015

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Brady posted:

I'm trying to create a pause function so that users can pause an operation. My code is set up something like so:

code:
    Public Function X
        For Each i In x
            If waitBox.Checked Then
                Wait()
            Else
                DoStuff()
            End If
        Loop
    Return Nothing
    End Function

    Public Function Wait()
        LogOutput("Application paused.")
        Do Until waitBox.Checked = False
            Task.Delay(1000)
        Loop
        LogOutput("Application unpaused.")
        Return Nothing
    End Function
This is probably obvious to most of you but it seems the issue with the above is that the GUI is entirely locked down when the DoStuff() code is running, and so the pause checkbox really doesn't do anything at all until the process is finished running, which defeats the purpose entirely.

I read something about making my application events separate from my GUI, but I'm not sure where to even start with that. Do I add a new module or something?

What is DoStuff doing? If it's an I/O bound operation (reading files, getting stuff from a web service, etc), use async/await. If it's a long-running CPU-bound operation, use Tasks or Background Workers. Background workers are conceptually simpler than Tasks.

Basically, your application starts out with 1 thread: The UI thread. Everything that your application does happens in this thread. There's something called the event loop in UI applications, and updating the UI happens as part of the event loop. Your application code also happens in the event loop. If you run something long-running in the UI thread, the event loop stops processing, your application "freezes", and you're sad.

Async/await solves the problem for I/O bound tasks by doing a lot of scary stuff under the covers to keep the event loop running while the other logic executes, but it all stays on the same thread and is much easier for someone who doesn't have a solid grasp of threading behavior to get a handle on.

Background workers solve the problem by letting you kick off an additional thread to handle the processing. You can't update the UI from that thread, so you have to call a method on your background worker to report progress back to the UI thread and update the UI accordingly.

New Yorp New Yorp fucked around with this message at 16:29 on Apr 13, 2015

Adbot
ADBOT LOVES YOU

raminasi
Jan 25, 2005

a last drink with no ice

Ithaqua posted:

Background orkers are conceptually simpler than Tasks.

I think calling Task.Run is easier than spinning up a BackgroundWorker, so is there something else I'm not thinking of?

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