Loading Dataset for two different sessions - c#

I am experiencing a problem with loading of my work order page.
When I load my page I am just passing the id of the work order WO.aspx?inspectionid=12345
Now on computer 1 I am loading
WO.aspx?inspectionid=1
Now on computer 2 I am loading
WO.aspx?inspectionid=2
To reproduce my issue I click the respective inspection on each separate computer at the exact same time (well as close as I can to a manual simultaneous click)
Now when I debug my LoadWorkOrder function in my code, it calls a stored procedure and populates a Dataset. Now before the first call completes and loads up the rest of the page, I see that my second call is already hitting my LoadWorkOrder function, thus causing one of the pages to error out.
So my question is, is there a way to properly handle multiple calls on the same function. Is this a threading related issue? I am not quite sure even what to google to help solve my issue.
private void LoadWorkOrder()
{
//Bizlogic.cInspectionsBizLogic.GetInspection(dstInspection, mintInspectionID);
dstInspection = new cInspectionsDST();
Bizlogic.cInspectionsBizLogic.GetInspection(ref objDataAdapterForUpdate, dstInspection, mintInspectionID);
if (dstInspection != null && dstInspection.Tables[0].Rows.Count > 0)
{
Bizlogic.cSchedulerDST dstItem = new cSchedulerDST();
dstItem = Bizlogic.cSchedulerBizLogic.GetScheduleItemForInspectionID(mintInspectionID);
LoadInspectionAddressHeader();
I don't see anything special here, its just a simple loading of a dataset. The error message I do seem to be getting "There is no row at position 0". Within my cInspectionsDST.Designer.cs file. These DataSets are created within Visual Studio I've inherited so changing those is unfortunately not an option.

dstInspection was a static variable once I removed that and reworked the code I no longer had this issue

Related

Console app quits before foreach loop finishes (C#)

This console app ends before reaching the end, i know that because it usually scans a whole Table in a DB with 5000-10000 rows.
I have no idea as to why it quits halfway, because it has no exeptions or any information (it just shows no information in the logs it just "stops"), and after aproximatly 10-15 mins it abruply stops and exits like everything is fine and it just reached the end of it. When i check the db only 1000-2000 registers have been worked on.
The Code : (Rather simple function any clarification ask and i shall give it, not a reproductive example because its a big development but i will point out what type of information everything is with as much detail as possible)
private List<Item> artigos;
public void VerifyID()
{
//a list cointaining all the rows in the db
artigos = itemCore.GetAllSEAAll();
foreach (var artigo in artigos.ToList())
{
try
{
//Code Here
}
catch(Exception ex)
{
logger.LogInformation(ex.ToString());
}
}
}
TL:DR on code :
I get 5000-10000 rows from a table.
I check a specific field on it and compare to a value (irrelevant for the question) that comes from an api.
I update the db in order to register any anomalies.
(Updated to include only needed code)
It will reproduce the problem i have its just least predictable as to how long until it stops, I am pretty sure it HAS something to do with Garbace Collector or Memory Management
I have so far tried to stop the garbage collector from collecting my variable (artigos).
Resulting is a few (3-5) results of (Object not Initialized) before it quits.
From debbuging i managed to figure out that List artigos, at some point stops existing, GC.KeepAlive() does nothing.
I have searched the web for a similar issue without any luck.
That being and my lack of experience i am currently stuck on what to do, or even what "path" to take to figure out, any help is welcome and sorry if i am missing anything im not familiar with StackOverflow structure
I need to make this clear, i have debuged this program more then i care to remember.
It is not my code that sets artigos to null.
There is no exeption being thown.

calling StateHasChanged() async in Blazor Server-Side application effects all open browsers, how can I stop this?

This is my first question here so please go easy on me. :)
I'm also new to Blazor but not c#.
I am building a Blazor server-side application where a user can enter some information and check if it's valid or not based on some data on the server.
So far I have no issues with calling the function of the class that does the lookup and returns a record to display on the browser.
My problem comes when I want to display that information.
In the c# code, I have a variable called SdItem which contains the record that comes back from the query.
To display the data on the razor page I use the following lines.
#if (SdItem != null)
{
<div>
Code: #SdItem.Code<br />
Desc.: #SdItem.Desc<br />
</div>
}
When SdItem gets the data it obviously does not display the information until I call StateHasChanged();
This of course throws an exception so I had to change it to await InvokeAsync(StateHasChanged);
Although after this change the information shows on the screen and all seems to be fine, I came across a new issue which I could not find a solution or an explanation anywhere on the internet.
During debugging, MS Edge automatically starts and displays the website.
To test this strange issue I also start Firefox to point to the same local address.
Then I use my smartphone as well and that is where I start the query.
When I get the results back, not only do they show up on the phone but on all active browsers that are currently displaying the site.
Why does this happen and how can I stop it.
At the moment I managed to stop this from happening with an ugly code
try { StateHasChanged(); } catch { }
This suppresses the exception and the result is only being displayed on the browser that does the request. This is ugly and I don't like to use it.
Any help would be appreciated.
Just as information, in case this could be the reason. The queried data is in a List in a class which is added as a scoped service. But T is a private variable in the code on the razor file.
"When SdItem gets the data it obviously does not display the information until I call StateHasChanged" Why is this obvious? I would expect Blazor to update the display whenever displayed data is changed. You should very rarely need to call StateHasChanged. This makes me wonder what else is going on.
First thought that springs to mind is that SdItem should be a property...
public Whatever SdItem { get; set; }
...and not a private field...
private Whatever SdItem;
I'm not sure if needs to be public, but when using properties, Blazor (almost) always updates the display. When using private fields, if often doesn't.
"This of course throws an exception" Again, I don't see why this is so obvious that you say "of course." It all depends on where you are calling StateHasChanged. Yes, if you're inside an async block then you'll need to call InvokeAsync, but if you arent, then you shouldn't need to do that.
More code would be useful, as its hard to know exactly what you're doing from the small snippet you provided, but try using a property (if you aren't already), and see if that avoids the need to call StateHasChanged.
If not, please update your question with more information.

C# [Persistent Saving and Loading]

Alright, so basically I have this slight issue that I'm trying to get a fix for. I'm using a GameObject called GameControl that I have learned from the Unity Tutorial guy. What I'm trying to do is be able to edit the options after they have been loaded. I can get them to save and load just fine. I had to switch the options up differently for the Singleplayer and Multiplayer mode because they have different save and load data. Now when I save/load this data back. I'm having troubles getting them to edit after loading, because it seems to be continuously loading the saved data, so if I were to make a change, it alters back to the saved data.
When I was just following along, I had this when the options were both the same and I used:
void Start() {
GameControl.control.Load();
}
Which seemed to work just fine, but now I have two different load files SP Options and MP Options. And I just don't know where to put these files, I thought maybe in my Switch Operation where I have it to load when I click Singleplayer, or when it loads Multiplayer at click. But this is where I have the continuous loading problem. And when I go to edit the options in the Window, it reverts back, please help me understand where to put these loads. I don't want to have a load button, I don't like the idea of that, I want it to be an automatic load, when you click Singleplayer (get singleplayer load files); and Multiplayer (get multiplayer load files).
void OnGUI() {
GUI.skin=mainSkin;
menuSelection=GUI.SelectionGrid(new Rect(Screen.width*.025f,Screen.height*.025f,buttonW,buttonH), menuSelection, button, 1);
switch(menuSelection) {
default:
break;
case 0:
windowRect=GUI.Window(0,windowRect,SPOptionsWindow,"Singleplayer Options (Pre-Game)");
break;
case 1:
windowRect=GUI.Window(1,windowRect,MPOptionsWindow,"Multiplayer Options (Pre-Game)");
break;
case 2:
LeaderboardsWindow();
break;
}
}
Here is where I have it loading the Load files; however I am unsure this is where it's supposed to be unless there is more code to make it stop running after the first time it loads. I've also tried to load it in the SPOptionsWindow(); and MPOptionsWindow(); but I get the same result.
Ahhhhh, long time fix! So basically what I did to correct this was to add more code in the GameControl.cs file. Although some features aren't the same, all I had to do was just recreate the same types with different naming conventions. More code, however it definitely works. However temporarily. Thinking long-term, however, I'm not sure if this is the exact fix that I would appreciate to have.
Problems may occur: •The actual options taking place would require more code to implement. •Maybe I won't be able to implement more code, but I would have to change it back to being the same?
These I don't really know until I reach that bridge, but however, it's a fix for now, and if there are any other answers to this, please throw your idea out there :)

ArgumentException when trying to add a child to Canvas

I have some mysterious ArgumentException I have been beating the whole day - still have no idea why does it happen.
I have the next simple method in my MainPage:
public void FavsRefresh()
{
favsCanvas.Children.Clear();
for (short i = 0; i < (App.Current as App).favUnits.Count; i++)
{
FavsItems tmpUnit;
(App.Current as App).favUnits.TryGetValue((App.Current as App).ids[i], out tmpUnit);
Canvas.SetTop(tmpUnit.subCanvas, i * 120);
favsCanvas.Children.Add(tmpUnit.subCanvas);
}
}
Here tmpUnit is an instance of my class FavsCanvas. Its code doesn't matter - it merges some elements into Canvas, which is called here subCanvas and a series of them must be added into parent Canvas, called favsCanvas.
The sense in all this, that we have several items initially and the user may delete existing and add new. Every time an item is deleted or added I call this procedure (including initially program loading).
The joke is that it works during loading and when I call it from another pages, but when I call it from class method throws an exception, besides it adds the first element properly and refuses to do that with others.
Every item has unique name, I even tried not to use names at all or use random ones - not a chance. I have no idea why this exception appears?!
I call this method using following:
MainPage.MPInstance.FavsRefresh();
This way works good from another pages, but from class - fails. I even left only one line (simple reload those items in Canvas):
private void FavMenuItem_Click(object sender, RoutedEventArgs e)
{
//Delete favorite
if (((MenuItem)sender).Header.ToString() == AppRes.FavsMenuDeleteFav)
{
MainPage.MPInstance.FavsRefresh();
}
}
The fun is that this code worked when I wrote it first a couple weeks ago, but now somehow stopped.
Another thing I tried is to make this particular call from a method in App.xaml.cs, which in its turn is called from the class, but it didn't help either.
In fact I have studied most of parameters - everything is the same in both cases: when it works and when not, except the place from where the method is called. But I don't see any proper alternative.
--- added 05 Aug.
I am not sure if it is important, but it always point the next line after the line where exception is thrown:
(the forum does not allow me to post images, so here.
I tried to move this method to class both to class itself and to App.xaml.cs - the same problem.
It works properly when is called during loading (my MainPage is Pivot and this page which contains this favCanvas is one of the pivots, but not the first) and when I call it from another page while overriding its OnNavigatingFrom. And when it is called while the the MainPage and this pivot is active. May be something with that?
Well guys, I still can't catch the reason itself, but at last have found a dirty way to walk around.
The page, for some reason, does not like to be modified when it is active (at least this way). So for now I am forced to simply redirect to another page, where I just call my method and then go back.
If you have some ideas, they are still of demand as my current was is like a crutch and I dislike it

code to identify the number

I got one problem while doing one TAPI application based project in C#. I'm using ITAPI3.dll
My problem is.. i'm not getting incoming call information. To get the incoming call information, i'm using the get_callinfo function, but it is showing empty message.
Did you try a different modem?
TAPI is very hardware dependent
This might be a useful MSDN starting point:
http://msdn.microsoft.com/en-us/library/ms726262%28VS.85%29.aspx
(if you didn't already have that url)
I'm just experiencing the same problem. When i debug, a openfiledialog opens asking me to open a file. i'm no sure what it is right now, will get back when i find something. So i just skips the line of code, what causes it to be empty.
I found what was causing the problem for me :
get_callInfo has 3 constructors : one returning object, one returning int and one returning string. For some reason, the one returning object is failing. So i tried the string constructor. This gave me all the information i need. I'll give an overview of all attributes you can choose from :
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CALLEDIDNUMBER);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CALLEDIDNAME);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CALLEDPARTYFRIENDLYNAME);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CALLERIDNAME);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CALLERIDNUMBER);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CALLINGPARTYID);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_COMMENT);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CONNECTEDIDNAME);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_CONNECTEDIDNUMBER);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_DISPLAYABLEADDRESS);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_REDIRECTINGIDNAME);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_REDIRECTINGIDNUMBER);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_REDIRECTIONIDNAME);
e.Call.get_CallInfo(CALLINFO_STRING.CIS_REDIRECTIONIDNUMBER);
hope this still helps

Categories