Beat one’s head against the wall

To waste one’s time trying to do something that is hopeless.

I was beating my head against the wall to try and convince my friend to come to the course.