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
Spudnewt
Mar 5, 2005
Batman touched my junk liberally.

Destroyenator posted:

I feel like there should be a more idiomatic way of doing it, but it works.

do initial requests using an HttpWebRequest instead of a web client. you can specify an HTTP request that only gets header information (e.g. Method = "HEAD").

try to set an object or add the valid request url to a list only if the list is empty or the object is null

Adbot
ADBOT LOVES YOU

TheEffect
Aug 12, 2013

chippy posted:

I'm afraid I don't know the answer to your specific question but this looks to be a good starting point:

https://msdn.microsoft.com/en-us/library/office/hh243703(v=office.14).aspx
https://msdn.microsoft.com/en-us/library/office/hh243697(v=office.14).aspx

edit: Looks like you would want to use the ConversationManager to get the Conversation that interests you, and then you can set the title via its 'Properties' Property dictionary, one of which is 'Subject', which I'm guessing is probably the title you want.

https://msdn.microsoft.com/en-us/li...office.14).aspx

Sorry, should've specified this was Lync 2013, but I looked around for that documentation and think I found the 2013 versions of the articles you linked, so thank you! I should really utilize MSDN more often.

EssOEss
Oct 23, 2006
128-bit approved

TheEffect posted:

I was just wondering if the following was possible with VB.Net-

I want to make an application that automatically names a group chat via Lync. Currently the way we do it (because we don't use Lync's persistent chat feature) is create a word document with the title of the Lync chat we want, open it open and click "Share" and then share by IM. Then you add people and when you start the conversation the title of the document is the title of the conference.

I know PS can obtain quite a bit of Lync data and do all sorts of things with it but I need this to be useable by employees who have limited rights, so assigning execution policy as unsigned wouldn't be possible for them to do, thus PS is out of the question... but can this be accomplished with VB.Net?


Why don't you just sign your scripts so everyone can run them, if you think it can be done via PowerShell?

raminasi
Jan 25, 2005

a last drink with no ice

EssOEss posted:

When spawning new processes and fiddling with their input/output streams, I always create a new thread for each stream and handle any synchronization manually. Perhaps wasteful in some sense but it has been rock solid so far, without any pesky little issues due to assuming an order of data consumption/generation.

I think this is what I'm going to do - when using separate threads, the process runs in under a second, but with the async way it takes more than ten. When I step through with the debugger nothing takes that long so I have no idea how to even begin solving the problem.

Mr Shiny Pants
Nov 12, 2012

Destroyenator posted:

I feel like there should be a more idiomatic way of doing it, but it works.
code:
open System
open System.Threading.Tasks
open System.Net
open Microsoft.FSharp.Control.WebExtensions

let getWinner urls =
    let result = new TaskCompletionSource<Uri * string>()
    let fetch url = async { let uri, client = new Uri(url), new WebClient()
                            try let! response = client.AsyncDownloadString(uri)
                                result.TrySetResult (uri, response) |> ignore
                            with _ -> () }

    async { do! List.map fetch urls |> Async.Parallel |> Async.Ignore
            result.TrySetException (Exception "all failed") |> ignore } |> Async.Start

    Async.AwaitTask result.Task |> Async.RunSynchronously

let urls = ["http://broken"
           ;"http://google.com"
           ;"http://dnsjkadnksja.dsnakldsaoni.net"
           ;"http://dsadsdsa"]

Thanks, this is wonderful. :) Now I need to figure out how it works. Thanks a bunch!

TheEffect
Aug 12, 2013

EssOEss posted:

Why don't you just sign your scripts so everyone can run them, if you think it can be done via PowerShell?

Because I don't control the certificate server for my org unfortunately.

Calidus
Oct 31, 2011

Stand back I'm going to try science!
Our third party order entry system uses SQL server on the backend(database A). I have number of table valued functions which I use to generate reports using a internal MVC web app, the web app calls them directly with System.Data.SqlClient. The web app has it's own database(B) and I use Entity framework, LINQ and lambas to make my life easy. I current have all those table valued report functions stored in database A. Is there any down side to moving all those functions to database B and adding them to the entity framework for easy of use?

zokie
Feb 13, 2006

Out of many, Sweden
I have a question that might be a bit stupid. I'm doing some experimentation with Win2D and I noticed that the Vector classes and Drawing methods all use floats, but the CanvasControl uses doubles for its Height and Width.

Why is that? Compatability with old stuff while using a smaller type for faster calculations? Does anyone have any insight into this?

Kuvo
Oct 27, 2008

Blame it on the misfortune of your bark!
Fun Shoe
anyone have recommendations for a good ASP.NET MVC 5 book?

crashdome
Jun 28, 2011
I've been using a practice of my own for well over a decade and I want to run it past everyone to see if I am behind the times or something.

Basically when you have a Parent->Child relationship in SQL where the Parent is more or less a description and the children are transactions, I leave cascading update/deletes open in SQL for ease of maintenance by the DBA or if there is an archiving feature or something. Sometimes I don't want to let a user delete a Parent and the entire history with it by accident in an application. To handle this in the past, I used to query the parent and children and then create a property to allow deletion. This property was dependent on the children being returned from the database and carried along with the parent object. I had my own type which was a three-phase Boolean. It basically returned CanDelete/NoDelete/NoData with NoData being returned if the children were lost or never returned from the database. This allowed me to choose what to do (e.g. reQuery, force delete, etc..) depending on the context at the moment.

Fast forward and I am using the Nullable Boolean instead. It works great because of the method GetValueOrDefault(T) which returns a value if it HasValue or a default value so you can choose what to do when Null. I've been using this like crazy. Problem is I am also using other Nullable types to represent Sums, Averages, Counts, etc... for display so for example:

code:
class MyModel
{
	ObservableCollection<Children> Transactions;

	public bool? CanDelete
	{
		get
		{
			return (Transactions.Count > 0 ? {Retrieve a bool if any transactions are of a certain type which should prevent delete} : Null);
		}
	}

	public decimal? TotalRemaining
	{
		get
		{
			return (Transactions.Count > 0 ? {Retrieve a sum} : Null);
		}
	}
}

class MyViewModel
{
	...Some Property for a Delete Command
	{
		//This method ensures if for some reason there are no transactions available it will not allow delete for safety because in this circumstance
		//every myModel should have a minimum of one transaction and if there are none, there is something inherently wrong
		//Alternatively, I could supply a default of true in the event I want to let the user delete something with no tranasactions.
		return myModel.CanDelete.GetValueOrDefault(false);
	}

	public decimal TotalRemaining
	{
		get
		{
			//Defaults a display of -1 which in this case, indicates to the user there is something in error - I don't want to halt 
			//or throw an exception because I actually want to leave it up to the user on how to deal with it. Maybe they delete 
			//or edit the object to correct the problem. Or maybe they bring it up to an administrator
			//Or maybe in a completely different ViewModel I throw an exception instead of using GetValueOrDefault
			return myModel.TotalRemaining.GetValueOrDefault(-1);
		}
	}
}
So you see in the comments the point is that in most of my use cases an exception is overkill and I want the application to resume, correct itself, or let the user decide. Oddly, most of these nullable Booleans are for safety and, almost never get used because *waves magic wand* all is right with my data layer. The other values just simplify displayed data and let my ViewModel deal with any errors in the way I want each ViewModel to handle it.

Is this bad? I have Nullable fields on almost all of my models similar to the above. It seems solid but, I have a nagging feeling I am overusing Nullable types and trusting something too much. Like they are inherently dirty and will stab me in the balls when I'm not looking.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost
So at work, I'm having a massive issue with Massive, and MySQL. Once every few days, the App Pool in our IIS server shits the bed. Looking at the event logs, I get:

quote:

Application: w3wp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an internal error in the .NET Runtime at IP 000007FD8437F230 (000007FD83D50000) with exit code 80131506.

Ooof, that's bad. What's worse is I can't replicate it on our Staging server, nor on my dev machine. Elmah got nothing either, as well as any of the other logging stuff we have set up. Basically, it just crashes, and I don't know why. So, in a fit of desperation, I put the IIS Debugger tools on to get a Minidump... in Production. :(

So once I got a dump, I turned off the debugger and took a look.

quote:

Unhandled exception at 0x000007FD89AA7B8C (KERNELBASE.dll) in w3wp__DefaultAppPool__PID__3392__Date__02_18_2015__Time_04_05_37PM__13__First Chance Access Violation.dmp: 0xC0000005: Access violation reading location 0x0000000000000040.

And the call stack:



So MySqlConnection tries to get the server version (for some reason), then it blows up... but this does not happen all the time. The start of the call stack is a normal call requesting data to be shown, and as far as I can tell there is nothing special about it. It just... happens. I thought it might have been an updated MySQL driver causing it, but I rolled that back to the version we had before and the same thing happens (Although less often it seems, but that's probably just happenstance).

Any ideas? Anything else I should look at? Myself and another web dev looked at my previous commits trying to see if I introduced something that would cause it, but from what we can tell there is nothing obvious from the changes I made that would cause this to happen.

Gul Banana
Nov 28, 2003

Your call stack explains the reason why it's trying to get the server version - New Relic is using it for analytics. You might have encountered a bug triggered by reentrancy, as i see that ServerVersion.get is ultimately being called within OpenConnection thanks to the analytic shim... does that require a connection to be already open? Does it open one itself? Either would be bad.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

Gul Banana posted:

Your call stack explains the reason why it's trying to get the server version - New Relic is using it for analytics. You might have encountered a bug triggered by reentrancy, as i see that ServerVersion.get is ultimately being called within OpenConnection thanks to the analytic shim... does that require a connection to be already open? Does it open one itself? Either would be bad.

I'm going to end up getting rid of NewRelic for now and see if that helps. It should be using the same database connection from what I can tell, but maybe something else in it is opening up another one? And only some of the time? I'm going all :psyduck: over it, but I asked around and it does not seem to be very useful for us at the moment so I can just turn it off.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Kuvo posted:

anyone have recommendations for a good ASP.NET MVC 5 book?

Pro ASP.NET MVC 5 by Freeman. I started reading it and a week later I was building a production site from scratch. It's not genius or a scintillating read but it works.

RICHUNCLEPENNYBAGS fucked around with this message at 02:36 on Feb 19, 2015

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

This is a hypothetical question I guess, since I've already done it, and it's going to be replaced by the real solution (make the proc on the database return the right results) eventually. But I found myself in need of filtering down one datatable based on the contents of another. I just threw together a quick and dirty Linq-y style thing since I knew it would work:
code:
Dim GoodProduct as datatable = (sql that makes a table with a SKU field)
Dim BadProduct as datatable = (sql that makes a table with an ItemCode field that matches SKU field)

Dim LLJK = From t1 in GoodProduct Join t2 In BadProduct on t1.Item("SKU") Equals t2.Item("ItemCode") Select t1

For each dr as DataRow in LLJK
 'My poo poo
Next
What I'm wondering, how performant is this? My past experience with Linq is that it's a neat way to write things out in a terse, yet mostly readable style, but it ends up being not so hot when it comes to performance. Was there a better way? Is this a bad way?

bobthenameless
Jun 20, 2005

Kuvo posted:

anyone have recommendations for a good ASP.NET MVC 5 book?

I am pretty new to the .net/mvc game myself, but this book is around at work and its been pretty good as a reference /overall view of things combined with MSDN docs for specifics.

I don't really have anything to compare it to, however, and there may be better ones out there.

raminasi
Jan 25, 2005

a last drink with no ice
I'm trying to play around with the profiler in VS2013, and I keep seeing "ThePreStub" show up. Is this just function call machinery? Googling just turns up references to ngen, which I'm not using.

bobua
Mar 23, 2003
I'd trade it all for just a little more.

RICHUNCLEPENNYBAGS posted:

Pro ASP.NET MVC 5 by Freeman. I started reading it and a week later I was building a production site from scratch. It's not genius or a scintillating read but it works.

I bought the beginner's version of this book a couple weeks ago and it was absolute poo poo. If you can write a for loop already get this 'pro' version.

Sab669
Sep 24, 2009

I've inherited a really, really sloppy application at work and I have done virtually no *real* web development to speak of. The application has an <asp:GridView> that gets its data source bound when the user clicks a Search button.

ViewEditProjects.aspx.cs:
code:
    private void Search()
    {
        DataSet dsGridView = new SqlDataAdapter();
        SqlConnection conn = new SqlConnection(myConnectionString);
        SqlDataAdapter daGridView = new SqlDataAdapter();

        daGridView = new SqlDataAdapter(mySQLstatement);
        daGridView.Fill(dsGridView);

        myGridView.DataSource = dsGridView
        myGridView.DataBind();
    }
ViewEditProjects.aspx:
code:
    <asp:GridView ID="myGridView" runat="server" AutoGenerateColumns="false"
         onpageindexchanging="myGridView_PageIndexChanging" >
    //bunch of columns manually written out
    <asp:BoundField DataField="myCol" HeaderText="myCol" SortExpression="myCol" />
    //more columns 
    </asp:GridView>
this 'myCol' BoundField can display 3 values: "Yes", "No", or "Select" (it's not a Mandatory field so whoever originally wrote this just writes Select to the DB). I'd just like to show an empty string in place of "Select" in the grid, is that possible?

I know BoundField has a NullDisplayText and DataFormatString property but I can't seem to achieve what I'm looking for with that.

RICHUNCLEPENNYBAGS
Dec 21, 2010

bobua posted:

I bought the beginner's version of this book a couple weeks ago and it was absolute poo poo. If you can write a for loop already get this 'pro' version.

I think "pro" means "for a professional programmer," not "for ASP.NET MVC pros."

Anyway this guy churns out like 10 books a year or something so I'm sure there's a lot of recycled content there.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Sab669 posted:

this 'myCol' BoundField can display 3 values: "Yes", "No", or "Select" (it's not a Mandatory field so whoever originally wrote this just writes Select to the DB). I'd just like to show an empty string in place of "Select" in the grid, is that possible?

I know BoundField has a NullDisplayText and DataFormatString property but I can't seem to achieve what I'm looking for with that.

You can listen for the RowDataBound event on the GridView. Then you can use something like this to change the values:

C# code:
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType != DataControlRowType.DataRow) return;

    // this is index based, so it's a little lovely - just find the cell you want to modify
    var cell = e.Row.Cells[0];

    if (cell.Text == "Select")
        cell.Text = "";
}

Sab669
Sep 24, 2009

e; nevermind stupid type-o. Thanks Bognar :D

Sab669 fucked around with this message at 16:33 on Feb 20, 2015

UncleBlazer
Jan 27, 2011

What's the best framework to go with for game dev? I just want to mess around with F# and have a little fun.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
Well, if you're using F# that rules out playing with Unity. XNA is dead since Microsoft doesn't support it anymore, but it's more like a Dawn of the Dead or 28 Days Later kind of dead where it can still run real fast and gently caress poo poo up. There's also SFML.Net and OpenTK, but I haven't played with either. I hear Duality is a good option for 2D style games.

I'd probably say go with XNA even though it's not supported, since you're just messing around. It probably still has the most documentation available, so it shouldn't be too hard to get something running.

EDIT: Maybe check out MonoGame? Never used it, but it looks like it will work with F#: https://bruinbrown.wordpress.com/2013/10/06/making-a-platformer-in-f-with-monogame/

Bognar fucked around with this message at 22:17 on Feb 21, 2015

Inverness
Feb 4, 2009

Fully configurable personal assistant.
I recommend MonoGame. It's coming along great. Just make sure you get one of the nightly builds which are quite stable. 3.2 doesn't have any of the new pipeline stuff that its in the nightly builds.

UncleBlazer
Jan 27, 2011

Thanks very much guys, I'll have a look at monogame. It'll make a change from parsers.

Centripetal Horse
Nov 22, 2009

Fuck money, get GBS

This could have bought you a half a tank of gas, lmfao -
Love, gromdul
Oh, God. I am not good with .Net. How did I get here?

I have an object (a big, complicated object with much inheritance, and not of my creation) which is owned by the main thread in a C# WPF application. I spawn a second thread that does all the meaty stuff, and some of that meaty stuff is dependent on the object in question. The meaty stuff will also occasionally make changes to the object, which will be reflected in the GUI. I need to pass the object back and forth between the threads, and I am just failing all over the place. It seems like, no matter what I do, I end up with those "owned by another thread" exceptions. I am starting to think crazy thoughts, like round-robin invoking between the threads. I've never had this problem, before, and I can't figure out what is different, this time.

Thread A: Creates object, assigns it as source of GUI element.
Thread B: Creates another object based on the first object. Does **something** to this new object, then turns around and publishes changes to the original object.

The above story is pure fiction, but it's what I'd like to see happen.

Inverness
Feb 4, 2009

Fully configurable personal assistant.

Centripetal Horse posted:

Oh, God. I am not good with .Net. How did I get here?

I have an object (a big, complicated object with much inheritance, and not of my creation) which is owned by the main thread in a C# WPF application. I spawn a second thread that does all the meaty stuff, and some of that meaty stuff is dependent on the object in question. The meaty stuff will also occasionally make changes to the object, which will be reflected in the GUI. I need to pass the object back and forth between the threads, and I am just failing all over the place. It seems like, no matter what I do, I end up with those "owned by another thread" exceptions. I am starting to think crazy thoughts, like round-robin invoking between the threads. I've never had this problem, before, and I can't figure out what is different, this time.

Thread A: Creates object, assigns it as source of GUI element.
Thread B: Creates another object based on the first object. Does **something** to this new object, then turns around and publishes changes to the original object.

The above story is pure fiction, but it's what I'd like to see happen.
WPF uses a threading model centered around dispatchers. Each thread has a dispatcher and DispatcherObject instances are bound to and only accessible by that one thread. Luckily DispatcherObject provides the Dispatcher it is bound to, which allows you to execute operations in a thread-safe manner.

Examine the Dispatcher class and decide which method you want to use. The ones that invoke the method synchronously on the dispatcher's thread will block the current thread until the operation is completed on the other thread.

For async stuff you want either InvokeAsync() which has new style tasks, or BeginInvoke() for the old style.

Here is a simple example:
code:
string text = await wpfObject.Dispatcher.InvokeAsync(() => wpfObject.Text);
Frozen objects do not have a dispatcher, since they're immutable and thus can be accessed from any thread.

Mr Shiny Pants
Nov 12, 2012

Centripetal Horse posted:

Oh, God. I am not good with .Net. How did I get here?

I have an object (a big, complicated object with much inheritance, and not of my creation) which is owned by the main thread in a C# WPF application. I spawn a second thread that does all the meaty stuff, and some of that meaty stuff is dependent on the object in question. The meaty stuff will also occasionally make changes to the object, which will be reflected in the GUI. I need to pass the object back and forth between the threads, and I am just failing all over the place. It seems like, no matter what I do, I end up with those "owned by another thread" exceptions. I am starting to think crazy thoughts, like round-robin invoking between the threads. I've never had this problem, before, and I can't figure out what is different, this time.

Thread A: Creates object, assigns it as source of GUI element.
Thread B: Creates another object based on the first object. Does **something** to this new object, then turns around and publishes changes to the original object.

The above story is pure fiction, but it's what I'd like to see happen.

Why do you need to pass it between threads?

Edit: Why do you need to create another object if the changes need to passed on to the other one? Why not update the object right away and update the UI accordingly?

Centripetal Horse
Nov 22, 2009

Fuck money, get GBS

This could have bought you a half a tank of gas, lmfao -
Love, gromdul

Inverness posted:

Examine the Dispatcher class and decide which method you want to use. The ones that invoke the method synchronously on the dispatcher's thread will block the current thread until the operation is completed on the other thread.

I am moderately familiar with Dispatchers, which is how I usually get things done between the UI and other threads. That's why I'm puzzled, here.

Mr Shiny Pants posted:

Why do you need to pass it between threads?

Edit: Why do you need to create another object if the changes need to passed on to the other one? Why not update the object right away and update the UI accordingly?

Maybe I don't. I'm not sure how to give a good explanation without going into boring detail about what I'm working on. The gist of it is, the object is going to undergo a large number of transformations before finding one that is suitable for display. I don't want to manipulate it directly and show all the intervening steps.

A quick rundown/overview:
User loads an image file through a standard dialog. This file is loaded into an object that is a descendant of the Bitmap class. That becomes the source for an image control on the GUI.
A thread is spawned to do the real work. This thread needs to create another object based on the original. The worker thread needs not only basic information such as height, width, pixel format, and so on, but also access to the actual pixels of the original.
Every once in a while, I want to update the object that is being shown by the GUI.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy
How big is the image? Will it cause significant performance problems to just make a copy of it and do your work on the copy in another thead? If not, just do that, then you're free to do whatever you want to the copy without worry about updating the UI, then you can sync back to the UI whenever.

Mr Shiny Pants
Nov 12, 2012

Bognar posted:

How big is the image? Will it cause significant performance problems to just make a copy of it and do your work on the copy in another thead? If not, just do that, then you're free to do whatever you want to the copy without worry about updating the UI, then you can sync back to the UI whenever.

I think this is exactly what he wants to do but he doesn't get it to work.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?
Are you trying to read the image from a picturebox in the worker thread or something? I'm not sure why else you'd get those exceptions.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Mr Shiny Pants posted:

I think this is exactly what he wants to do but he doesn't get it to work.

I guess I misunderstood what he was saying - the way I read it, it seemed like he was working with the same object in both threads. Seeing some code would really help here.

Centripetal Horse
Nov 22, 2009

Fuck money, get GBS

This could have bought you a half a tank of gas, lmfao -
Love, gromdul

Bognar posted:

How big is the image? Will it cause significant performance problems to just make a copy of it and do your work on the copy in another thead? If not, just do that, then you're free to do whatever you want to the copy without worry about updating the UI, then you can sync back to the UI whenever.

The image can be of any size. I am not too worried about the overhead of passing it around. If it becomes an issue, I can just adjust the frequency of the updates.


Mr Shiny Pants posted:

I think this is exactly what he wants to do but he doesn't get it to work.

Bognar posted:

I guess I misunderstood what he was saying - the way I read it, it seemed like he was working with the same object in both threads. Seeing some code would really help here.

I would prefer to work on one object, but I've been failing. I fail just as badly if I try to make a copy specifically for the worker thread. I guess I can try re-opening the file from the worker thread, and re-doing whatever work is involved in loading and pre-processing the image, but I don't like the sound of that. I'm far enough along that it would be tough to separate out just the bits in question.


HappyHippo posted:

Are you trying to read the image from a picturebox in the worker thread or something? I'm not sure why else you'd get those exceptions.

It's am Image control, which I think is equivalent to a PictureBox. I get the "owned by another thread" exceptions whether I try to use the Bitmap-descended object, or try to access the control.

It's been a couple of years since I did anything in WPF/.Net, but I don't recall ever having quite this issue.

I'm starting to feel like a bit of a dick for wasting everyone's time, because I am sure this is just me missing some fundamental concept. I haven't run into this problem, before.

HappyHippo
Nov 19, 2003
Do you have an Air Miles Card?

Centripetal Horse posted:

It's am Image control, which I think is equivalent to a PictureBox. I get the "owned by another thread" exceptions whether I try to use the Bitmap-descended object, or try to access the control.

It's been a couple of years since I did anything in WPF/.Net, but I don't recall ever having quite this issue.

I'm starting to feel like a bit of a dick for wasting everyone's time, because I am sure this is just me missing some fundamental concept. I haven't run into this problem, before.

It's been awhile but I believe you can't access a control from a thread other than the one it was created in. With winforms you had to use InvokeRequired / Invoke to get access. Some googling tells me you have to use Dispatcher to do the same with WPF. So maybe you should look into that?

ljw1004
Jan 18, 2005

rum

Centripetal Horse posted:

Oh, God. I am not good with .Net. How did I get here?

I have an object (a big, complicated object with much inheritance, and not of my creation) which is owned by the main thread in a C# WPF application. I spawn a second thread that does all the meaty stuff, and some of that meaty stuff is dependent on the object in question. The meaty stuff will also occasionally make changes to the object, which will be reflected in the GUI. I need to pass the object back and forth between the threads, and I am just failing all over the place. It seems like, no matter what I do, I end up with those "owned by another thread" exceptions. I am starting to think crazy thoughts, like round-robin invoking between the threads. I've never had this problem, before, and I can't figure out what is different, this time.

Thread A: Creates object, assigns it as source of GUI element.
Thread B: Creates another object based on the first object. Does **something** to this new object, then turns around and publishes changes to the original object.

The above story is pure fiction, but it's what I'd like to see happen.

I'd go about this entirely a different way. The insight is
* Pretty much most of your code can be done fine on the UI thread because it's not CPU-intensive
* There are a few CPU-intensive bits but these are generally "pure functions" that take in some input, give back an output, and don't need access to all the objects in memory.

So do most of your code on your single UI thread. That way you don't need to worry about thread-safety. When you encounter the small piece of code which has a compute-intensive inner loop, then run only the smallest part of it you can on a background thread via Task.Run. For instance,

code:
img.Description = "hello " + DateTime.Now.ToString()
img.Subtitle = "world"
var convolveMatrix = GetImageConvolutionMatrix();
img.PixelBuffer = await Task.Run(() => ConvolvePixels(convolveMatrix, img.PixelBuffer.Copy()))
Picture1.ImageSource = img.PixelBuffer

...
byte[] ConvolvePixels(double[,] matrix, byte[] pixels)
{
   // this is a computationally-expensive inner loop
   for (int x=0; x<1024; x++) for (int y=0; y<1024; y++)
      pixels[y*1024+x] = ...
}
Oh, and if your compute-intensive inner loops DO need access to random parts of the objects you have in memory rather than being pure functions? then refactor them!

raminasi
Jan 25, 2005

a last drink with no ice

Centripetal Horse posted:

I would prefer to work on one object, but I've been failing. I fail just as badly if I try to make a copy specifically for the worker thread. I guess I can try re-opening the file from the worker thread, and re-doing whatever work is involved in loading and pre-processing the image, but I don't like the sound of that. I'm far enough along that it would be tough to separate out just the bits in question.

...

I'm starting to feel like a bit of a dick for wasting everyone's time, because I am sure this is just me missing some fundamental concept. I haven't run into this problem, before.

Are you copying the object reference, or are you actually copying the image bytes over? This is really hard to diagnose without code.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Any of you guys ever had to programmatically connect to Google drive and grab the content for use/insertion into a database? We've got a marketplace that we're doing good sales on, but they have zero automation for sales reporting, order importing, etc. So the way our staff keep track of them is to update a Google Spreadsheet Doc. The idea being I'd connect to Drive, open this sheet, and grab new rows and put them in the database.

I've found and am messing around with this:
https://developers.google.com/resources/api-libraries/documentation/drive/v2/csharp/latest/annotated.html

But am just wondering if anyone else has done it and if they have any 'gotchas' or advice.

Adbot
ADBOT LOVES YOU

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
VS2015 CTP 6 came out earlier today, along with the first CTP of TFS 2015, with all the awesome new build stuff.

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