0

I'm currently working on a scenario where I am developing an activity for UiPath. The class library is a project setting where I am creating this activity. Specifically, for this activity, I am using Winforms, and the class library (activity) will launch and pass a DataTable to the WinForms project. My question is: How can I establish communication between two different projects, each having its own DLL file?

One potential solution I considered is to include both projects in the same solution. However, the activity is implemented as a class library (.NET Framework), and the WinForms project is separate. How can I reference System.Activities and System.ComponentModel in the class file that I am manually creating in the WinForms project?

Class library (Activity):

using System;
using System.Activities;
using System.ComponentModel;
using System.Data;

namespace Datatable_Visualizer_Activity
{
    public class DatatableVisualizer : CodeActivity
    {
        [DisplayName("Datatable")]
        public InArgument<DataTable> Datatable { get; set; }

        protected override void Execute(CodeActivityContext context)
        {
            DataTable dt = Datatable.Get(context);
        }
    }
}

Winforms:

using MaterialSkin;
using MaterialSkin.Controls;
using System.Data;
using System.Drawing.Drawing2D;
using System.Reflection;
using System.Windows.Forms;

namespace Data_Table_Visualizer___Editor
{
    public partial class MainForm : Form
    {
        

        public MainForm()
        {
            this.DoubleBuffered = true;
            InitializeComponent();
            dataGridView.Visible = false;
            ShowLoading(true); // Show the circular progress bar
            InitializeDataGridViewAsync();
        }

        private void ShowLoading(bool show)
        {
            // Show or hide the circular progress bar based on the 'show' parameter
            progressBar.Visible = show;
        }

        private async void InitializeDataGridViewAsync()
        {
            // Use the DataTable from the event
           private DataTable dataTable = ;//Datatable which i wanted to get from activity;

            await Task.Run(() =>
            {
                // Simulate a delay for loading data (replace this with your actual data loading logic)
                System.Threading.Thread.Sleep(3000);

                // Invoke on UI thread to update UI controls
                Invoke(new Action(() =>
                {
                    // Bind the DataTable to the DataGridView
                    dataGridView.DataSource = dataTable;
                    dataGridView.DoubleBuffered(true);
                    // Auto resize columns
                    dataGridView.AutoResizeColumns();

                    // Set labels based on the initial state
                    label_TotalNoColumns.Text = "Total No Of Columns = " + dataTable.Columns.Count.ToString();
                    label_TotalNoRows.Text = "Total No Of Rows = " + dataTable.Rows.Count.ToString();
                    ShowLoading(false); // Hide the circular progress bar
                    dataGridView.Visible = true; // Show the DataGridView
                }));
            });
        }

        /* private void CreateDataTable()
        {
             int totalRows = 10000; //Billion No Rows Count 1000000000
             int totalColumns = 100;  // Ten Lakhs no rows count 1000000
             int batchSize = 10000;

             // Create columns
             for (int i = 1; i <= totalColumns; i++)
             {
                 dataTable.Columns.Add($"Column{i}", typeof(int));
             }

             // Batch processing with parallelization
             Parallel.For(0, (totalRows - 1) / batchSize + 1, batch =>
             {
                 DataTable tempTable = new DataTable("MyDataTable");

                 // Add columns to tempTable
                 foreach (DataColumn column in dataTable.Columns)
                 {
                     tempTable.Columns.Add(column.ColumnName, column.DataType);
                 }

                 for (int row = 1; row <= batchSize && (batch * batchSize) + row <= totalRows; row++)
                 {
                     DataRow dataRow = tempTable.NewRow();

                     // Assign sample values to each column
                     for (int col = 0; col < totalColumns; col++)
                     {
                         dataRow[col] = (batch * batchSize) + row;
                     }

                     tempTable.Rows.Add(dataRow);
                 }

                 lock (dataTable)
                 {
                     dataTable.Merge(tempTable);
                 }
             });
         }*/

        private void dataGridView_ColumnAdded(object sender, DataGridViewColumnEventArgs e)
        {
            e.Column.FillWeight = 10;    // <<this line will help you
        }
    }

    public static class ExtensionMethods
    {
        public static void DoubleBuffered(this DataGridView dgv, bool setting)
        {
            Type dgvType = dgv.GetType();
            PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
            pi.SetValue(dgv, setting, null);
        }
    }
}

And in the end both the dll file will be added into a nuget pakage for use in uipath

7
  • 2
    I really don't get the question. Why would there be any problem? You can reference a library in your GUI project and then create class instances and call methods, register for events from its namespaces.
    – Fildor
    Commented Dec 28, 2023 at 9:59
  • Well actually i dont have much knowledge in winfroms and class library , im just starting out , i thought that sending data between two dll file maybe be difficult Commented Dec 28, 2023 at 10:12
  • "You can reference a library in your GUI project and then create class instances and call methods, " Like this :- imgur.com/a/cgzfTCi Commented Dec 28, 2023 at 10:14
  • If it were hard, then somebody would have come up with something better by now. The whole purpose of a library is to reuse code. So making it hard to use would really be nonsensical.
    – Fildor
    Commented Dec 28, 2023 at 10:35
  • 1
    I'd strongly advise to not use "&" in project names - or any names for that matter.
    – Fildor
    Commented Dec 28, 2023 at 10:36

1 Answer 1

1

Add a reference to the class library in your WinForms project and/or write

using [location and name of class in classlibrary = namespace]

above the code in which you want to use those classes.

The classes, properties and/or methods from the class library you want to use, need to be set to public in order to be able to use them across different projects. So

public [class name] or public [propery name]

3
  • 1
    Sometimes instead of making internal classes public and visible to "everyone", you can also use [assembly: InternalsVisibleTo("ProjectA")] to expose internal classes selectively. In this case, if you place this attribute in a ProjectB then an assembly named ProjectA now has visibility without having to resort to reflection to obtain it.
    – IV.
    Commented Dec 28, 2023 at 13:19
  • 1
    Cool! I was wondering sometimes if something like this existed, but never came across it. It does add the work of updating those specifications of to which parts things should be exposed. But maybe for specifically sensitive stuff that extra step of carefulness is good.
    – Miles
    Commented Dec 28, 2023 at 13:24
  • 1
    @Miles Thank you so much for the asner, now what i did is i made a class library project and in there i add a form (basically i copied the forms from previous project), and in MainForm() i added MainForm(Datatable datatable) {this.datatable = datatable} this solved my problem Commented Dec 29, 2023 at 5:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.