|
The DoWorkEventArgs class includes an Argument Property[^]
You can set that to an instance of any class (or struct) to pass whatever you need in.
It also contains a Result[^] property for passing completed data back to the caller via the RunWorkerCompleted Event[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Is it possible to pass more than one instance of any class? Do I need to use List<t> in this case?
|
|
|
|
|
You can use any object - so an int , a MyClass , a collection of IEnumerable objects, an array ... literally anything you need to.
Just be aware that you are multithreaded so you need to ensure thread safety if the argument data is going to be even looked at by two different threads, and that Control derived classes can only be accessed from the thread that created them (the UI thread).
But you almost certainly knew that ... I added it for those other readers who are just getting started with threading.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I used the following code for getting data from SQLite:
private void dataPager_OnDemandLoading(object sender, Syncfusion.UI.Xaml.Controls.DataPager.OnDemandLoadingEventArgs args)
{
List<int> list = new List<int>()
{
int.Parse(args.StartIndex.ToString()),
int.Parse(args.PageSize.ToString())
};
BackgroundWorker worker = new BackgroundWorker();
worker.WorkerReportsProgress = false;
worker.DoWork += worker_DoWork;
worker.RunWorkerAsync(list);
}
void worker_DoWork(object sender, DoWorkEventArgs e)
{
List<int> value = (List<int>)e.Argument;
List<Equipment> data;
using (var _sqliteContext = new SQLiteContext())
{
data = _sqliteContext.Equipments.Include(x => x.CostCenter).Skip(value[0]).Take(value[1]).ToList();
}
this.Dispatcher.Invoke(() =>
{
dataPager.LoadDynamicItems(value[0], data);
(dataPager.PagedSource as PagedCollectionView).ResetCache();
});
}
There is no runtime error but the table in the UI is empty.
|
|
|
|
|
Start with the debugger and see what data contains before you start the Invoke.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I debugged. Before Dispatcher.Invoke, the data is full of 50 records. But something happens in Dispatcher.Invoke and prevent data to be shown in the UI.
modified 16-Jul-22 2:16am.
|
|
|
|
|
Could it be that in worker_DoWork your variable data is going out of scope when the function ends?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Your BackgroundWorker is going to go out of scope; I haven't used that pattern so if it gets "busy", it will be hard to tell, if at all.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Assuming you have to call the LoadDynamicItems from within the event handler, moving the data-loading code to a background thread really won't accomplish anything. You'll still need to block in the event handler until the background thread has finished, so you'll be using two threads to do what you're currently doing with one.
You'll also potentially run into issues if you're working in a framework with a concept of a "UI thread"; the control will most likely expect the LoadDynamicItems method to be called from the UI thread, not a background thread, so you'll end up getting an exception.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm using Syncfusion in my WPF MVVM project. I want to add pagination to my datagrid. The following code can do this:
private void dataPager_OnDemandLoading(object sender, Syncfusion.UI.Xaml.Controls.DataPager.OnDemandLoadingEventArgs args)
{
using (var _sqliteContext = new SQLiteContext())
{
dataPager.LoadDynamicItems(args.StartIndex, _sqliteContext.Equipments.Include(x => x.CostCenter).Skip(args.StartIndex).Take(args.PageSize));
(dataPager.PagedSource as PagedCollectionView).ResetCache();
}
}
The problem is that when I run the code, the application falls into the break mode and says:
Quote: System.ObjectDisposedException: 'Cannot access a disposed context instance. A common cause of this error is disposing of a context instance that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
Object name: 'SQLiteContext'.'
How can I fix it?
modified 15-Jul-22 2:28am.
|
|
|
|
|
Code4Ever wrote: This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. Try reworking without the using statement.
|
|
|
|
|
Thanks. Solved using the following code rework:
private void dataPager_OnDemandLoading(object sender, Syncfusion.UI.Xaml.Controls.DataPager.OnDemandLoadingEventArgs args)
{
List<Equipment> data;
using (var _sqliteContext = new SQLiteContext())
{
data = _sqliteContext.Equipments.Include(x => x.CostCenter).Skip(args.StartIndex).Take(args.PageSize).ToList();
}
dataPager.LoadDynamicItems(args.StartIndex, data);
(dataPager.PagedSource as PagedCollectionView).ResetCache();
}
|
|
|
|
|
I had installed freespride in my asp net core project.
in the view of the controller i have this:
Spire.Doc.Document document = new Spire.Doc.Document();
but i got this error
TypeLoadException: Could not load type 'spride' from assembly 'Spire.Pdf, Version=8.2.2.0
The component it is installed, why the error?
Thanks
|
|
|
|
|
There are so many reasons that this could occur. It might rely on a version of an assembly that you have the wrong version of. You might be missing a dependency somewhere. Plus numerous other reasons. If the full stack of the error doesn't tell you (and we certainly can't from a one-line trace), use depends.exe[^] to see if you can identify missing or incorrect assemblies.
|
|
|
|
|
What is "spride" and where are you trying to load it?
|
|
|
|
|
Hello,
I have a project in vs2019, actually i have the following error and i can not find the error neither in google nor in microsoft, it is says is in line 1, but i can not go to the find.
Any help?
|
|
|
|
|
JSDoc indicates that this is a JavaScript/TypeScript issue and has nothing to do with C#.
|
|
|
|
|
Great, I know nothing about typescript, and i did not touch (because i nothing about typescript) any code of typescript, this mean: How did a made this error if i don not kwon? o How to fix?
Thanks
|
|
|
|
|
What type of project do you have here? Have you searched through your code for @extends?
|
|
|
|
|
I have searched @Extends, i have it, but all are // or */ but i did not touched those files.
I even knew their exists.
I loaded the project (ASPNET CORE with C#) on a different computer and the error just disapear.
Why? I don't know
|
|
|
|
|
That suggests that there is something wrong with you project settings. If this is genuinely a C# project then please show the line(s) of code where the error occurs.
modified 4-Jul-22 13:08pm.
|
|
|
|
|
The above tool is now deprecated, what is a good alternative that works well, complements Selenium? I use Visual Studio / C#. Thank you
|
|
|
|
|
I know you need Java to run this toolkit, but JMeter[^] is hard to beat for this. It is easier to use than something like Loadrunner, and integrates well with Selenium.
|
|
|
|
|
Thanks for the reply. I have come across JMeter, and you are right it is Java that is the deal-breaker for me thanks anyway
|
|
|
|
|
I have a table that store person data. There are NamePrefix and NameSuffix columns in the data. Both are nullable.
Here is the Persons table
CREATE TABLE [dbo].[Persons]
(
Id INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
RemoteId UNIQUEIDENTIFIER NOT NULL,
ClientRepId INT NULL FOREIGN KEY (ClientRepId) REFERENCES Persons(Id),
SupervisorId INT NULL FOREIGN KEY (SupervisorId) REFERENCES Persons(Id),
PersonType INT NOT NULL,
Prefix INT NULL,
FirstName VARCHAR(MAX),
LastName VARCHAR(MAX),
NickName VARCHAR(MAX),
Suffix INT NULL,
Title VARCHAR(MAX)
)
Here is the PersonEntity
namespace CLOI.Entities
{
public class PersonEntity : _EntityBase
{
private PersonType _PersonType;
public PersonType PersonType
{
get { return _PersonType; }
set
{
SetProperty<PersonType>("PersonType", ref _PersonType, value);
}
}
private NamePrefix _Prefix;
public NamePrefix Prefix
{
get { return _Prefix; }
set
{
SetProperty<NamePrefix>("Prefix", ref _Prefix, value);
}
}
private string _FirstName;
public string FirstName
{
get { return _FirstName; }
set
{
SetProperty<string>("FirstName", ref _FirstName, value);
}
}
private string _LastName;
public string LastName
{
get { return _LastName; }
set
{
SetProperty<string>("LastName", ref _LastName, value);
}
}
private string _NickName;
public string NickName
{
get { return _NickName; }
set
{
SetProperty<string>("NickName", ref _NickName, value);
}
}
private NameSuffix _Suffix;
public NameSuffix Suffix
{
get { return _Suffix; }
set
{
SetProperty<NameSuffix>("Suffix", ref _Suffix, value);
}
}
private string _Title;
public string Title
{
get { return _Title; }
set
{
SetProperty<string>("Title", ref _Title, value);
}
}
public string FullName
{
get { return $"{FirstName} {LastName}"; }
}
private int _ClientRepId;
public int ClientRepId
{
get { return _ClientRepId; }
set
{
SetProperty<int>("ClientRepId", ref _ClientRepId, value);
}
}
}
}
I'm trying to get this to work:
results = (from p in dc.Persons
select new PersonEntity
{
RemoteId = p.RemoteId,
ClientRepId = p.ClientRepId ?? 0,
SupervisorId = p.SupervisorId ?? 0,
PersonType = (PersonType)p.PersonType ?? PersonType.None,
Prefix = (NamePrefix)p.Prefix ?? NamePrefix.None,
FirstName = p.FirstName,
LastName = p.LastName,
NickName = p.NickName,
Suffix = (NameSuffix)p.Suffix ?? NameSuffix.None,
Title = p.Title,
CreatedById = p.CreatedById,
CreatedDT = p.CreatedDT,
LastModifiedById = p.Id,
LastModifiedDT = p.ModifiedByDT.Value,
DeletedById = p.DeletedById,
DeletedDT = p.DeletedByDT.Value
}).Where(predicate).ToList();
It's throwing a null ref exception because both the NamePrefix and NameSuffix columns are null.
I tried to change those lines like this:
Prefix = (NamePrefix)p.Prefix ?? NamePrefix.None,
But that won't compile with "
Operator '??' cannot be applied to operands of type 'PersonType' and 'PersonType' "
What's the right way to do this?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 2-Jul-22 15:40pm.
|
|
|
|