|
Multi-tasking "file operations" isn't as great as it sounds. Often the whole thing will run slower due to head and channel contention.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Say for example,
I wanted to send an array of integers from my C++ exe to C# at runtime
|
|
|
|
|
Well I just said it. Now what?
|
|
|
|
|
Did you consider using sockets or (named) pipes? Or some other IPCs?
|
|
|
|
|
i tried using namedpipes it just sends and receives but, My goal is to pass the elements from C++ and get that Elements at runtime in C# and process them. Like, Get n inputs in c++ and process that n elements in C#.
Eg: I am entering 5 inputs, say 1,2,3,4,5 in C++
where c# should get that inputs and process ( eg: inputelement + 1 )
the output would be 2,3,4,5,6.
C++ file
#include <windows.h>
#include <iostream>
HANDLE fileHandle;
int main()
{
fileHandle = CreateFileW(TEXT("\\\\.\\pipe\\pipesample"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
const char* msg = "hello from c++\r\n";
WriteFile(fileHandle, msg, strlen(msg), nullptr, NULL);
}
C# File
static void Main(string[] args)
{
var namedPipeServer = new NamedPipeServerStream("pipesample", PipeDirection.InOut, 1, PipeTransmissionMode.Byte);
var streamReader = new StreamReader(namedPipeServer);
namedPipeServer.WaitForConnection();
Console.WriteLine($"read from pipe client: {streamReader.ReadLine()}");
namedPipeServer.Dispose();
}
modified 23-Apr-21 6:19am.
|
|
|
|
|
I use SQL CE as a database file in my project. I need to load hidden ID numbers into my datatable. What is the command for accessing ID in SQL CE?
|
|
|
|
|
There isn't a "command for accessing ID" specifically, it's just a field within your table, so you use a normal SELECT statement.
To fetch the last inserted IDENTITY value (if that is what you are using for the ID, and it probably should be that or a GUID) just issue a SELECT @@IDENTITY on the same Connection object without closing it first, as @@IDENTITY is local to the Session, and closing the Connection will clase the Session as well.
"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!
|
|
|
|
|
Why would you do this? There is virtually never a good reason to do so.
Typically, this is done by noobs who think in terms of a single user using the database, never thinking of the possibility that more than one user can execute this same command at the same time and get the same answer. Now each instance of the code (and the person who wrote it) thinks they've got exclusive use of a number multiple people have.
|
|
|
|
|
Alex Dunlop wrote: What is the command for accessing ID in SQL CE? SELECT ID FROM table WHERE ...
|
|
|
|
|
I have used the following Class for saveing/reading DataGridView row and text color into/from an XML file. It works fine, but when I use column filters, all those color information got lost. Even when I remove the filters, there is no color in my texts/rows. (*** I use advanced DataGridView***)
My Class for load/save XML:
public static void WriteDataGridViewSettings(System.Windows.Forms.DataGridView dgv)
{
XmlTextWriter writer = new XmlTextWriter(Application.StartupPath + @"\MyGridColor.xml", null);
writer.WriteStartDocument();
writer.WriteStartElement(dgv.Name);
int LastRow = dgv.Rows.Count;
for (int i = 0; i < LastRow; i++)
{
writer.WriteStartElement("Row");
writer.WriteStartElement("CellColor");
writer.WriteString(dgv.Rows[i].DefaultCellStyle.BackColor.ToArgb().ToString());
writer.WriteEndElement();
writer.WriteStartElement("TextColor");
writer.WriteString(dgv.Rows[i].DefaultCellStyle.ForeColor.ToArgb().ToString());
writer.WriteEndElement();
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();
}
public static void ReadDataGridViewSettings(System.Windows.Forms.DataGridView dgv)
{
XmlDocument xmldoc = new XmlDocument();
XmlNodeList xmlnode;
FileStream fs = new FileStream(Application.StartupPath + @"\MyGridColor.xml", FileMode.Open, FileAccess.Read);
xmldoc.Load(fs);
xmlnode = xmldoc.GetElementsByTagName("Row");
for (int i = 0; i <= xmlnode.Count-1; i++)
{
int cellcolor = int.Parse(xmlnode[i].ChildNodes.Item(0).InnerText.Trim());
int textcolor = int.Parse(xmlnode[i].ChildNodes.Item(1).InnerText.Trim());
if (cellcolor != 0)
{
dgv.Rows[i].DefaultCellStyle.BackColor = Color.FromArgb(Convert.ToInt32(cellcolor));
dgv.Rows[i].DefaultCellStyle.ForeColor = Color.FromArgb(Convert.ToInt32(textcolor));
}
else
{
dgv.Rows[i].DefaultCellStyle.BackColor = Color.White;
dgv.Rows[i].DefaultCellStyle.ForeColor = Color.Black;
}
}
fs.Close();
}
How can I solve this problem?
modified 21-Apr-21 11:18am.
|
|
|
|
|
What you said is: it doesn't work; filter or no filter.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Filtering causes redrawing of all the rows and my color information is lost.
Of course, I need to use a hidden column for assigning an index code for each row, so I save the index color and load it. In this way, I can relocate those color information when using filtering.
|
|
|
|
|
I'm "guessing" that filtering is creating a "new" uncolored view; you might try and (re)color after applying the filter.
(It's a guess, so the troll need not get excited)
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Did you say that I'm trolling?
I just want to get help and solve my problem. It's all.
|
|
|
|
|
No, he didn't call you a troll.
He's making a comment in an attempt to head off the trolls.
|
|
|
|
|
thank you for help. the previous explanation does make sense but when about instance how yo accesss it from other class? thank you
class felhasznalo
{
adatlista adat = new adatlista();
foreach (string elem adat.lista)
{
}
}
|
|
|
|
|
Every time you "new up" adatlista , you are creating a new list, separate from any other instance.
So, if you new up two lists and add items to the one of them, you will NOT see those items in the other list.
|
|
|
|
|
thank you for help. I don't want to create new list just access the existing one from other classes possibly with foreach or for loop, recoed by record, thank you.
|
|
|
|
|
You might want to try something like this:
class felhasznalo
{
private adatlista adat = new adatlista();
public adatlista items { return adat; }
} You can now access adat from outside your class.
The simple idea behind this concept is that you are exposing a property that allows external access to members of your class, but does it in a controlled manner. This is why I wrapped this in a property. You could, just make adatlista a public field and allow classes access to the public field but that's a separate debate.
modified 21-Apr-21 3:13am.
|
|
|
|
|
Hi
thank you for help.
In my modified instance I placed recordlist is a separate class to be able to access it from various classes but access issues occured. please help me to access the record list type thank you.
<pre>using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace metjelentes
{
class adatok
{
public string telepules = " ";
public string ido = " ";
public string szeliranyes_erosseg = " ";
public int homerseklet = 0;
}
class adatlista
{
public List<adatok> lista = new List<adatok>();
}
class beolvasas
{
public void beolvas()
{
string olvas = @"c:\Users\Public\textfiles\tavirathu13.txt";
using (StreamReader sr =new StreamReader(olvas, Encoding.Default))
{
int db = 0;
while (!sr.EndOfStream)
{
string sor = sr.ReadLine();
string[] elemek = sor.Split(' ');
adatlista.lista.Add(new adatok());
adatlista.lista[db].telepules=elemek[0];
adatlista.lista[db].ido = elemek[1];
adatlista.lista[db].szeliranyes_erosseg = elemek[2];
adatlista.lista[db].homerseklet = Int32.Parse(elemek[3]);
db++;
}
Random rd = new Random();
int rand_num = rd.Next(1, db);
}
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
|
|
|
|
|
adatlista is not a variable, it's a class:
class adatlista
{
public List<adatok> lista = new List<adatok>();
}
So you can't access it's list like this:
adatlista.lista.Add(new adatok());
Why not?
Because you need an instance of the class to work with ...
Let's ignore computers for a moment, and talk about cars.
We both have a car: the same make, the same model, the same colour, the same engine, the same age.
I give you a ride to the shops, and while in my car, you put your mobile phone in the glove box.
When you get home again, you need you mobile so you go to your car and open the glove box. Is your phone there?
No, of course not - it's in the glove box in my car. You know that it can only be accessed my opening my car, opening that glove box and reaching in for your phone, because you know that the two vehicles are separate instances of the particular class of black Mercedes A-class cars that they made in 2006.
You know that despite being outwardly identical, they are very different vehicles and that to do anything with them, you have to use the right instance. You want to drive to the airport, you take your car, not mine!
Classes and instances also matter in computers: Car is a class, but "your car" is a Car type variable which holds a Car class instance, "my car" is another Car type variable which holds a different Car class instance.
So you access the List in your adatlista class, you need to create an use a specific instance of that class:
adatlista adat = new adatlista();
adat.lista.Add(new adatok());
There is a way to get what you wrote to work, but ... it's probably something you haven't really covered yet: static classes - so I won't go into that. It's pretty important that you understand instances anyway!
Does that make sense?
"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!
|
|
|
|
|
where view doesn't know about presenter, just raises events... presenter knows views controls (idk how to do the one where to make the presenter as if it was calling a console, for unit tests...)
1. should view contain ui logic, or all logic is in the presenter?
2. if view event is raised, should presenter call view's method or should presenter do the magic and tell view what control to change?
3. We're using a single form like sidebar with many usercontrols in the main panel, should presenters be separate from each other? even the main one?
4. When calling dispose to save resources, what happens to the presenter it's associated to? i get an error because the view is not there because deleted, check if null, create one with unity? what lifetime manager? should i dispose presenter too? how do i recreate it then if yes?
5. unity what lifetime manager is best? it's in the program.cs
thank you all in adv )
|
|
|
|
|
Hi
I try to load txt file data in record list in object but error msg stops code running. the error is below.
Severity Code Description Project File Line Suppression State
Error CS1955 Non-invocable member 'StreamReader' cannot be used like a method. metjelentes C:\Users\Dell\source\repos\metjelentes\metjelentes\Program.cs 21 Active
<pre>using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace metjelentes
{
class adatok
{
public string telepules = " ";
public string ido = " ";
public string szeliranyes_erosseg = " ";
public int homerseklet = 0;
}
class beolvasas
{
public void beolvas()
{
string olvas = @"c:\Users\Public\textfiles\tavirathu13.txt";
using (StreamReader sr = StreamReader(olvas, Encoding.Default))
{
List<adatok> lista = new List<adatok>();
while (!sr.EndOfStream)
{
string sor = sr.ReadLine();
string[] elemek = sor.Split(' ');
lista.Add(new adatok());
}
}
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
|
|
|
|
|
Remove the ( between using and streamreader
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
You have this:
using (StreamReader sr = StreamReader(olvas, Encoding.Default))
You have to "new up" a StreamReader to get an object for it:
using (StreamReader sr = new StreamReader(olvas, Encoding.Default))
|
|
|
|